While browsing through C++ code in VS Code, I am looking for a better way (possibly just a simple keyboard shortcut after some configuration) to do the following:
MyClass
class).At present I don't know a better way then to copy the symbol name -> Ctrl + Shift + F -> paste the name -> hit 'Enter'.
As of version 1.42.0 there is no single-keystroke way of doing it (although I would appreciate this very much).
You could use the sequence Ctrl-D, Ctrl-Shift-F.
("Add Selection To Next Find Match")
Better: There is an extension exactly for this use case, it's called:
"Search Under Cursor"
I added a single keychord method to my extension: Find and Transform. So if you set up a keybinding like:
{
"key": "alt+z", // whatever keybinding you like
"command": "runInSearchPanel"
}
you can trigger the keychord when the cursor is on (or immediately after) a word or select a word and the Search Panel will open with that word as the query.
The command can also take a lot of arguments, like:
{
"key": "alt+z",
"command": "runInSearchPanel",
"args": {
"find": "(?<=^Arturo)\\d+", // fixed-width lookbehinds and multiline supported
"replace": "###",
"matchWholeWord": false,
"isRegex": true,
"filesToInclude": "${file}", // resolves to current file
"triggerSearch": true
}
}
and other args
if you want to save a pre-defined search as a keybinding or as a setting that will be exposed in the Command Palette. More at the README.
Previous Answer:
You don't have to copy or paste the symbol, just highlight all of it. You can do that in various ways such as double-clicking the word or I like the vscode expand region extension. Then Ctrl-Shift-F and Enter to perform the search.
This is assuming you have
// Controls if we seed the search string in Find Widget from editor selection
"editor.find.seedSearchStringFromSelection": true,
in your settings. true is the default.
[ Apologies to @yorammi if this is what you said, I couldn't follow your instructions ... ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With