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

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.

Related

How to hide suggestions on known words in Visual Studio Code?

Suggestions are very useful, but sometimes they're annoying.
I want to hide suggestions when what I typed is a known word in the language or in the current document.
E.g.: Since I used the word elapsed in a document, every single else I typed after it selected elapsed. Very annoying. Since else is a known word, I want the suggestions disappear, so when I hit ENTER the final word is that what I typed. This is a case; there are a lot of cases.
Other editors hide suggestions on known words (e.g.: Kate).
Tuning "editor.quickSuggestionsDelay" doesn't help, because frequently I stop to think and suggestions will appear anyway.
"editor.acceptSuggestionOnEnter": false doesn't help too; I've tried it but I'm not productive using TAB instead of ENTER.
I also tried "editor.wordBasedSuggestions": false, but this is not what I want. It hides every known word, but I want to select known words if I didn't type one.
I would like an option like "editor.hideSuggestionsOnKnownWord": true, but I could not find nothing similar in vscode.
Is there an option or an extension to do that?

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

Any way to manually trigger highlighting of semantic symbol occurrence in 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

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.

ignore differences in syntax in beyondcompare

In a branch of code I have changed all of the code from obj.varname to obj("varname") and when I compare the code I would like to ignore these differences since varname is the same.
I have a regular expression that I think I need but unfortunately can't get the comparison to be ignored using Beyond Compare from Scooter
^obj\("\w*"\)|obj\.\w*$
I am following this tutorial http://www.scootersoftware.com/support.php?zz=kb_unimportantv3
So my question: is this even possible with beyond compare? If yes, please share a solution including either instructions or post your screenshots.
Beyond Compare 3's Professional edition supports this through its Text Replacements feature. If you've already purchased a Standard edition license you need to revert to trial mode to test it: http://www.scootersoftware.com/suppo...?zz=kb_evalpro
Load your two files in the Text Compare.
Open the Session Settings dialog from the the Session menu, and on the Replacements tab click New to create a new replacement.
In the Text to find edit, use (\w+)\.(\w+)
In the Replace with edit, use $1("$2")
Check the Regular expression checkbox.
The alternative would be to mark any instance of obj.varname and obj("varname") as unimportant. The basic steps would be this:
Load your two files in the Text Compare.
Open the Session Settings dialog from the Session menu, and on the Importance tab click the Edit Grammar... button.
In the next dialog click the New... button below the top listbox.
Change the Element name field to something useful (say, "PropertyAccess").
Change the Category* to List.
In the Text in list* edit, add these two lines:
obj.varname
obj("varname")
Click OK to close the Grammar Item dialog and then click OK again to close the Text Format* grammar item.
Uncheck "PropertyAccess" (or whatever you named it) in the Grammar elements listbox in the Session Settings dialog, then click OK to close it.
This approach isn't as flexible or clean. In the steps above you're matching specific, hardcoded object and variable names, so obj.varname is unimportant but obj.othervar isn't, even if it's aligned against obj("othervar"). If text on both sides is unimportant the difference will be unimportant; if one side is important it will be an important difference. So, with the above steps, obj.varname and obj("varname") will be unimportant everywhere, but it will work correctly since they'll either be matched to other cases that also match those definitions (and thus unimportant) or will be matched to something else that doesn't match that definition, which will be important and will make the difference important.
You can use regular expressions to match more general text categories, but you probably don't want to. For example, if you wanted to match all text that followed that pattern you could use these two lines instead:
\w+\.\w+
\w+\("\w+"\)
And then check the Regular expressions checkbox in the Grammar Item dialog so they're matched that way.
The upside/downside to that is that any text that matches those patterns is then unimportant. abc.newvar vs. def.varname would be considered an unimportant difference because both sides match the unimportant definition. That's good for things like comments or whitespace changes, but probably isn't what you want to do here.