Any way to manually trigger highlighting of semantic symbol occurrence in Visual Studio Code? - visual-studio-code

In VSCode, when you place cursor inside a symbol (variables, functions, etc), all occurrence of the same symbol will be highlighted.
This feature is somewhat useful but annoying as well. Even I can make it less obtrusive by customizing the color theme in settings.json, it will suppress the selection highlighting when you select a variable by double clicking it with mouse cursor.
I've learned that I can completely disable this feature by adding "editor.occurrencesHighlight":false in settings.json, but this feature is still useful because it can label occurrences of a symbol with different color, to represent read/write status of each occurrence.
So my question is: is there any way to disable the automatic semantic matching feature, and only enable it manually with keyboard shortcuts or commands ?

If you only need textual matches, you can select some text use the Select all occurrences of find match command. This will select every occurrence of the selected text in the current document (and also create a cursor at it)
For symbol based information, try using the Find all references or Peek references commands. The flow is different but it gives the same information.
Alternatively, use an extension like this one to create a keyboard shortcut that toggles editor.occurrencesHighlight

Related

VS Code find-and-replace: is there a way to keep my previous find term when I type ctrl+h?

Currently, when I use ctrl+h with something highlighted, my find term is set equal to the highlighted text. Is there a way to stop that (and keep my find term the same as it was previously)?
Often I want to find-and-replace in VS Code, do something, highlight something, and then find-and-replace the same thing again. Is there a way to make it so that I don't have to retype my find term a second time?
I know there are some plugins that have this functionality; if you know of any that allow me to see both my find and replace terms at the same time, I would like to know.
Set this setting to false:
// Controls if we seed the search string in Find Widget from editor selection
"editor.find.seedSearchStringFromSelection": false,
Editor > Find: Seed Search String From Selection
Doing this will also affect your Find/Search in Files functionality.

Search and find a word in a block of code in VSCode

I'm trying to search for a word in a block of code (a function, a class, between two {} and so on...) in VSCode. the default search is searching in the whole file but that is not useful in some situations.
It is easy to restrict your search key to a block of code select your block of code to search and then click on the Find in selection option on the find widget (left one to the close option from the image)
See the Find in selection option here

VSCode will copy full line when only a word is selected (single click)

I'm on OSX and running Version 1.42.0 of Visual Studio Code. I have noticed that when I single click a word it will highlight. But if I copy CMD + c and then paste CMD+v, the full line will be in the clipboard. This causes problems from time to time, when the screen has given me every indication that I have only selected a single word. Is there some setting that I can set that will make the default behavior to select a word on a single quote and never ghost select a full line?
What it looks like when I single click a word:
And what it looks like after I've copied and pasted:
After filing an issue, it turns out that this behavior is by design.
The word the cursor is on (from a single click) is highlighted along with every occurrence of that word. The word is not selected (that would be a deeper blue).
By default copying without a selection copies the current line.
This in my opinion is an Accessibility issue, as there are strong visual clues that a word is selected. I have found that the behavior can be made more intuitive if you set these to settings.
// Controls whether copying without a selection copies the current line.
"editor.emptySelectionClipboard": false,
// Controls whether the editor should highlight semantic symbol occurrences.
"editor.occurrencesHighlight": false
With these two settings the word the cursor is on will not be highlighted (nor any other occurrences of that word). And if you do happen to copy, with an empty selection, the editor will behave similar to how other applications behave and not copy the current line.

VS Code Refactoring: Change all occurences - but only in block scope

When using "change all occurences" in VS Code, it will just search the whole file for matches and change them. Is there a similar feature doing the same thing, but limiting it to function or block scope?
Let's take an example where I would need that: I'm having a React file with several components and want to refactor a class component to a functional component, so I'm changing all occurences of this.props to props. However, I obviously don't want to change all the other class components as well that are supposed to stay class components. :-)
This seems like such a standard use case, but I'm not able to find it anywhere in VS Code. If it's not possible (yet, or for some good reasons) is there another way to achieve what I'm trying to do?
Check out the 'Add Selection To Next Find Match' functionality. It allows you to highlight the first occurrence you'd like to change, then using a keyboard shortcut, highlight the next occurrence and so on until you've selected all the instances you want to change. When all to-be-changed occurrences are selected, you can edit the selected text normally. Just remember to hit the escape key a couple times after editing to return to a single cursor!
Here are the keybindings for the command, it's Cmd+d on Mac:
https://code.visualstudio.com/docs/getstarted/keybindings
I find it very useful when renaming variables, there's also a shortcut to skip occurrences (Cmd+k Cmd+d) in case there is text you don't want to change in between.

MS Word Hidden Formatting Marks

There is a problem with the formatting of certain .docx files. I click to show the hidden formatting marks. There are degree symbols ("non-breaking spaces") in between many of the words, instead of a regular space.
To solve the problem: I copy and paste the degree symbol, and then I use the "find and replace" function to replace the degree symbols with a regular space.
How do I prevent this problem from occurring in the first place?
Or, how can I automatically convert these symbols to a regular space.
Non-breaking spaces are used to keep words from breaking across lines.
As Cindy stated above, the simplest way to remove them manually is to record a macro and execute this from a Ribbon button or the Quick Access Toolbar.
According to this link (and this link it refers to), nonbreaking spaces are inserted automatically if your proofing language is set to French and you type certain characters. To prevent this from happening, you have to either use a different proofing language or disable the "Replace straight quotes with smart quotes" option. To do this, see below (and I'm quoting the previous link):
To change the proofing language, select the text and click Language on
the Review tab. In addition to choosing another language, it's a good
idea to uncheck the option to automatically detect the language.
To change the quotes replacement, click File > Options > Proofing >
AutoCorrect Options, choose the AutoFormat As You Type tab of the
dialog (not just AutoFormat), and uncheck the first option.