In VSCode working in a file, and you need to change multiple variable etc.
When selecting all occurrences in a file,
I often find that I need to de-select one or more,
can you do that?
On Mac, to de-select one or more substrings selected with Cmd + D, type Cmd + U.
Analogously, type Ctrl + U on Windows/Linux.
Found on https://www.reddit.com/r/vscode/comments/8gx98z/how_cancel_last_ctrld_selection/
Assuming you use Ctrl+D to select multiple variables, press K while still holding Ctrl to skip/exclude the current selection.
You can use your multi-cursor add command to also de-select specific cursors. So if you have this setting:
Editor: Multi Cursor Modifier
The modifier to be used to add multiple cursors with the mouse. The Go
To Definition and Open Link mouse gestures will adapt such that they
do not conflict with the multicursor modifier. Read more.
set to alt (the default) then you can alt+left-mouse-click them in any order to deselect them. Or same with Ctrl/Cmd if that is your setting option.
If you use the find widget to find all your occurrences (select a word and Ctrl+F) then alt+enter will select them all from the start. Then you can deselect any of them with the alt+left-mouse-click thing. and then if you want them all reselected for any reason alt+enter will do that.
See demo for both methods (right-click vs find widget).
I want to change all default keyboard shortcuts starting with 'Ctrl + K' to something else (say 'Alt + K'). Is there any way in Visual Studio Code to do that at once?
I know that it can be done by selecting one Keyboard shortcut at a time, but is there a way to do this all at once, something similar to Find/Replace of keyboard shortcuts?
This might help:
f1 -> open keyboard shortcuts.
Press brackets button on top right.
Cut all of your preferences and save them in another file without the first and last square brackets.
First step again.
Search for ctrl k.
Select the first one - press and hold delete -> Delete all of them (This is easy!).
On the top right click on the brackets button. (Open keyboard shortcuts(json)).
Deleted shortcuts have been added to this file with a - behind them on the command value. Each have an opening bracket, key value, command value, and closing bracket.
Select one of the opening brackts, then press and hold ctrl+d.
Double press down arrow, then home button.
Delete the first - from all of the command values with this trick.
Then go to the key values and change them all to what you want. Please note that some of them may be in ctrl+k+... form, but some others in ctrl+alt+k+... or ctrl+shift+k+... form. You can't change them with this trick!
I Ctrl + click through various function definitions, in Go. Sometimes I drill too deep. I want to move up the stack of visited files. How do I do this in VS Code?
You can use workbench.action.navigateBack and workbench.action.navigateForward to quickly move back and forth between recent cursor positions.
The default keybinding for workbench.action.navigateBack is Alt+LeftArrow
The default keybinding for workbench.action.navigateForward is Alt+RightArrow
If your mouse has buttons on the side, you can use them in place of the above keybindings.
By default:
Alt+LeftArrow moves you back.
Alt+RightArrow moves you forward.
To assign your custom key combinations, click on the
File -> Preferences -> Keyboard Shortcuts.
or just press CTRLK + CTRLS
Type workbench.action.navigateBack double click on the found line and assign your shortcut key combination for moving Back and similarly, assign your Forward shortcut by typing workbench.action.navigateForward and double clicking on the result.
Note:
Pay attention to message while you are trying to assign the new combination. If the key combination already assigned for something else, VsCode will warn you.
On linux, default keybindings are:
workbench.action.navigateBack = CTRL+ALT+-
workbench.action.navigateForward = CTRL+SHIFT+-
Are there any trick or extension to select all instances of selected word in visual studio code, to facilitate editing or deleting those instances without search and replace, like ِAlt+F3 in sublime text
Select All Occurrences of Find Match editor.action.selectHighlights.
Ctrl+Shift+L
Cmd+Shift+L or Cmd+Ctrl+G on Mac
According to Key Bindings for Visual Studio Code there's:
Ctrl+Shift+L to select all occurrences of current selection
and
Ctrl+F2 to select all occurrences of current word
You can view the currently active keyboard shortcuts in VS Code in the Command Palette (View -> Command Palette) or in the Keyboard Shortcuts editor (File > Preferences > Keyboard Shortcuts).
What if you want to select just a few?
No problem, first:
Ctrl+F find the letters by typing them
ESC to quit searching
(you need to do this even when using
Ctrl+Shift+L
to select all occurences)
OR
just select those letters with your mouse or keyboard
(Shift+arrows)
Now that the mouse cursor is blinking on your first selection,
using a few more Key Bindings (thanks for the ref j08691)
you may:
Ctrl+D select (add) the next occurrence
Ctrl+K+Ctrl+D skip
the current/latest occurrence and add the next occurrence
Ctrl+U undo the latest cursor operation
on Mac:
select all matches: Command + Shift + L
but if you just want to select another match up coming next: Command + D
If you want to do one by one then this is what you can do:
Select a word
Press ctrl + d (in windows).
This will help to select words one by one.
On Ubuntu:
Ctrl + F2 will select all occurrences immediately.
Ctrl + D will select occurrences one by one.
In my MacOS case for some reason Cmd+Shift+L is not working while pressing the short cut on the keyboard (although it work just fine while clicking on this option in menu: Selection -> Select All Occurences). So for me pressing Cmd+FN+F2 did the trick (FN is for enabling "F2" obviously).
Btw, if you forget this shortcut just do right-click on the selection and see "Change All Occurrences" option
Ctrl+Shift+L to select all occurrences of current selection.
Several options have been listed, but a couple are missing. Its possible to use the rename and refactoring tools, for not just selecting all, but making specific changes, after everything has been selected. I am going to try and bundle all answers I feel are relevant together, and add two more that, not only get the job done, but are really great tools for making single changes over multiple occurrences of the same code.
1. Select All Matches
To use multiple cursors to select all matches, you can use 1 of 2 keybindings. Both keybindings preform the same functionality, so in other words, 2 keybindings, 1 vscode command. The keybindings are as follows.
1. CTRL + F2
2. CTRL + SHIFT + L
Default Keybinding
{
"key": "ctrl+f2",
"command": "editor.action.changeAll",
"when": "editorTextFocus && !editorReadonly"
}
// You can view/customize VSCode keybindings by pressing F1 and typing Keybindings
2. Select Next Match
You can Select Next Match by using the keybinding below. This is good for selecting all occurrences within a specific vicinity.
CTRL + D
Default Keybinding
{
"key": "ctrl+d",
"command": "editor.action.addSelectionToNextFindMatch",
"when": "editorFocus"
}
SIDE NOTE
If you press the keybinding CTRL + K before pressing CTRL + D, instead of selecting the next instance, it will move you to the next instance, and target it with your cursor.
Default Keybinding
3. Rename
This one hasn't been mentioned yet, but this one is what you would except when doing a refactor in a traditional IDE, like Visual Studio 2022, or JetBrains: IntelliJ.
When you use this keybinding, it attempts to solve some of the problems that are incurred when using the other options listed above. The other options are overly greedy sometimes, and select parts of words that you didn't want to select, and if your not careful, you can delete quite a bit of code, resulting in messy situation. If you didn't notice that you screwed up right away, you end up saving, or working for a long while before having to reset everything, and you end up loosing a lot of work & time.
F2 attempts to solve this problem by implementing logic under the hood (IDK if its an algorithm or what it is) but it feels very much like refactor in Visual Studio. It only selects specific cases that you would want to target. So if a varable is named foo, is won't select foo from a var named fooFoo. It also won't select foo from a comment.
F2
{
"key": "f2",
"command": "editor.action.rename",
"when": "editorHasRenameProvider && editorTextFocus && !editorReadonly"
}
4. Find
This one I will keep short and sweet, but find will iterate through ever occurrence of a pattern that you type into the editor-widget.
Press CTRL + F then type what you want to select. Keep pressing ENTER until you find it.
5. The Best For Last
There is not one method for selecting all occurrences that is the best every time, that's why there are several different methods for doing it, however, there are some methods that are generally more useful than others. This feature, as far as I know, is unique to VS Code, and I use it all the time when working with large JSON files, and Large Code Bases (like an Open Source PR).
VS Code has its own search editor, its a special editor. You can open the search editor by pressing on the Magnifying Glass Icon on the Activity-bar. Type into the search editors side bar text-input what it is you want to select, then press ENTER. It will return all the results in the sidebar. You can use the lower text input, to replace all of the results with what ever you like. You can also click OPEN IN THE EDITOR (it looks like a link) and it will reproduce everything you searched for in a new document, that is opened to the side. From there you can manipulate it, and add it back to the document. I've already written enough for one answer, so I am not going to go to deep into every thing it can do, but this not only selects everything, it also extracts it, replaces it, lets you nit-pick exactly what it means to select "all" of a specific occurrence. It's a great tool for making a single change in a recursive fashion.
This seems an old question, but it worth an answer.
There is - besides the accepted answer - a fancy shortcut to do this, just select the desired word and press Ctrl + D as many times as desired, each press will select an exact occurrence in the editor, after all occurrences are selected, just type the replacement and all the occurrences will be replaced as you type.
Ctrl + F2 works for me in Windows 10.
Ctrl + Shift + L starts performance logging
I needed to extract all the matched search lines (using regex) in a file
Ctrl+F Open find. Select regex icon and enter search pattern
(optional) Enable select highlights by opening settings and search for selectHighlights (Ctrl+,, selectHighlights)
Ctrl+L Select all search items
Ctrl+C Copy all selected lines
Ctrl+N Open new document
Ctrl+V Paste all searched lines.
I had another application, called Loom, running in the background on my Mac which was taking over my keyboard bindings.
Cmd+Shift+L
It was just random that I figured out it was preventing the keyboard bindings from reaching VS Code. I tried to turn off applications that I had open one by one. Not the best approach, but it worked.
Additionally to unselect use
Cntrl + U
When I am comparing two files in Eclipse (using, for example, "Compare With" --> "Local History"), what keyboard shortcuts are available?
I would like to be able to go to the next/previous diff and copy the selected diff left without having to click the tiny little buttons.
Thanks!
To complete Artem's answer, after Preferences->General->Editors->Keys, search for:
Select next change
Select previous change
Copy from Left to Right
Copy from Right to Left
All those keys in the "Compare" section have no shortcut assign by default, so you can add the ones of your choice.
Set your own keys as instructed by #Artem and #VonC.
In Eclipse Galileo, however, the path is Window > Preferences > General > Keys.
For each command you wish to set:
Click on the Command Name
TIP: Sort by "Category" to group all "Compare" commands.
Click on the "Binding" textbox
Then, select the keys you wish to use, Eclipse will record them for you.
TIP: You can enter a sequence of keys in addition to key combination(s).
Set "When" drop down box to "Comparing in an Editor."
TIP: This setting will limit your hot key(s) to only be activate in the chosen context.
Intuitive Hot Key settings: (my recommendations, not from a standard)
Copy All from Left to Right Ctrl+Shift+Left, Ctrl+Shift+Right
Copy All from Right to Left Ctrl+Shift+Right, Ctrl+Shift+Left
Copy from Left to Right Ctrl+Left, Ctrl+Right
Copy from Right to Left Ctrl+Right, Ctrl+Left
Select next change Ctrl+Down
Select previous change Ctrl+Up
With eclipse, when you are in a window and you have a button to do a action but this button doesn't have a tooltip to show you his shortcut, go to Navigate menu.
The most of time, shortcuts are shown there.
Actually you can define whatever you want to be a short cut for this. Preferences->General->Editors->Keys.
EDIT:
For some reason I don't see that option appears there. O_o
There is a catch. There are no Next Difference and Previous Difference entries in the key bindings editor. These two buttons in a compare window are bind to Next and Previous entries in the key bindings editor. See Is there a key binding for Next Difference and Previous Difference in Eclipse Compare Editor?
I raised a bug at https://bugs.eclipse.org/bugs/show_bug.cgi?id=401129 which can be voted on.