Reputation: 10857
What are the keyboard shortcuts for creating multiple cursors in VS Code?
Upvotes: 904
Views: 772810
Reputation: 12473
Press Alt and click. This works on Windows and Linux*, and it should work on Mac, too.
More multi-cursor features are now available in Visual Studio Code 0.2:
Multi cursor improvements
- Ctrl+D (Cmd+D on Mac) selects next occurrence of word under cursor or of the current selection
- Ctrl+K Ctrl+D moves last added cursor to next occurrence of word under cursor or of the current selection
The commands use matchCase by default. If the find widget is open, then the find widget settings (matchCase / matchWholeWord) will be used for determining the next occurrence- Ctrl+U (Cmd+U on Mac) undoes the last cursor action, so if you added a cursor too many or made a mistake, you can press Ctrl+U (Cmd+U on Mac) to go back to the previous cursor state.
- Adding cursor up or down (Ctrl+Alt+Up / Ctrl+Alt+Down) (Cmd+Alt+Up / Cmd+Alt+Down on Mac) now reveals the last added cursor to make it easier to work with multiple cursors on more than 1 viewport height at a time (i.e. select 300 lines and only 80 fit in the viewport).
This makes it a lot easier to introduce multiple cursors
gsettings
as mentioned in another answer.Upvotes: 901
Reputation: 1220
For selecting same place on multiple lines just by keyboard and without using mouse (checked and worked on windows 10):
ctrl
+ alt
+ shift
+ ↓ (down arrow key)
Upvotes: 0
Reputation: 4445
Easy VSCode multiline cursor guide for Windows and Mac. If you tried and noticed very confusing keyboard instructions and could not sort it out, I provide very easy and simple way:
Windows:
Starting from one line and selecting multiple lines manually:
Keep Alt + Ctrl + Shift
pressed and move to upper or lower lines with keyboard arrows.
To add anything to both - the beginning and end of all lines at the same time:
Ctrl + A
- select allAlt + Ctrl + Shift
+ Down arrow from the keyboard - You will see multiple line start and end cursors blinkingAlt + Ctrl + Shift
pressed and use Right arrow to brings cursors to the right side end of words.If you want to add one symbol to all lines:
Ctrl + A
- select allAlt + Ctrl + Shift
pressed and press the Down arrow from the keyboard once.Macbook MacOS:
Starting from one line and selecting multiple lines manually:
Keep Alt + Command + Shift
pressed and move to upper or lower lines with keyboard arrows.
To add anything both - to the beginning and end of all lines at the same time:
Command + A
- select allAlt + Command + Shift
+ Down arrow from the keyboard - You will see multiple line start and end cursors blinkingAlt + Command + Shift
pressed and use Right arrow to brings cursors to the right side end of words.If you want to add one symbol to all lines:
Command + A
- select allAlt + Command + Shift
pressed and press the Down arrow from the keyboard once.Upvotes: 2
Reputation: 38867
There is no binding for exactly what you want.
The only thing that comes close is Ctrl+F2 which will select all of them at once.
You can bind it to Ctrl+D doing the following:
File > Preferences > Keyboard Shortcuts
It should look something like this:
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "ctrl+d",
"command": "editor.action.changeAll",
"when": "editorTextFocus"
}
]
Upvotes: 19
Reputation: 633
Multiple cursor on selected word
Use case - if you have a large document and want to modify some word or select a line containing that word.
I'll walk through with one example
Suppose you have a document (of any type) like
{
x: xval1,
y: yval1,
z: zval1
},
{
x: xval2,
y: yval2,
z: zval2
},
{
x: xval3,
y: yval3,
z: zval3
}
You want to select all the values associated with x and expecting output like this \
x: xval1,
x: xval2,
x: xval3,
Steps to achieve this output using vscode only -
I want to emphasise on the second step how much strong this command can be.
Upvotes: 0
Reputation: 1
First go to "Keyboard Shortcuts", you can get there by hitting Cmd+k then Cmd+s, or for Windows Ctrl+k then Ctrl+s.
Once you're there, search for "Add Cursor Above" and "Add Cursor Below". You can even assign them your own key-bindings.
Upvotes: 0
Reputation: 99
For xfce users, just go to settings>window manager tweaks>accessibility
there change the key used to grab and move windows:
to super
as demonstrated in the image below.
Now you can use super instead of alt. Wallah!! Go make multiple cursors by alt + click.
Upvotes: 6
Reputation: 17871
Windows / OS X:
For multi-line selection, Ctrl+Alt+Down / ⌘+Alt+Shift+Down will extend your selection or cursor position to the next line. Ctrl+Right / ⌘+Right will move to the end of each line, no matter how long. To escape the multi-line selection, hit Esc.
See the VS Code keybindings (OS sensitive)
Upvotes: 291
Reputation: 1179
Try Ctrl+Alt+Shift+⬇ / ⬆, without mouse, or hold "alt" and click on all the lines you want.
Note: Tested on Windows.
Upvotes: 115
Reputation: 4880
Cmd+Option+Shift⬇ / ⬆ works for me on newest VSCode 1.29.1 and newest OSX High Sierra 10.13.6, Macbook Pro.
This adds a vertical line up/down on screen, like Option+Click/Vertical Drag does in Sublime Text.
To add multiple cursors at any points in your file, including multiple ones on the same line, do Cmd (or Option)+Click anywhere you want, shown in this video. You may also search for text (Cmd+F) that repeats multiple times, then press Option+Return to add cursors at end of EACH word.
Upvotes: 62
Reputation: 999
On XFCE, go to Applications -> Settings -> Settings editor - > xfwm4 -> easy_click(disable value)
Now you can Insert Cursor
with Alt + Click
I've also disabled L/R Workspace (ctrl + alt + L/R) settings in Settings -> Window manager -> Keyboard
Upvotes: 34
Reputation: 7738
Ctrl+Alt+⬇ / ⬆ add cursors above and below the current line. Still nowhere near as good as sublime or brackets though. I can't see anything equivalent to Ctrl+D in sublime in the keyboard shortcuts file.
Upvotes: 19
Reputation: 380
Alt+Click. It works in Windows.
Details: Visual Studio Code Documentation
Upvotes: 9
Reputation: 2431
You can do the following per the Selection menu:
Press/hold Alt+Ctrl+Up Arrow/Alt+Ctrl+Down Arrow as required to create sufficient cursors, then Ctrl+D can be used to expand the selections.
Upvotes: 5
Reputation: 308
In my XFCE (version 4.12), it's in Settings -> Window Manager Tweaks -> Accessibility
.
There's a dropdown field Key used to grab and move windows:
, set this to None
.
Alt + Click works now in VS Code to add more cursor.
Upvotes: 8
Reputation: 41
Alt + Command + Shift will add a cursor to the next instance of what you've selected. E.g. a variable or function name
Upvotes: 2
Reputation: 3600
May 2017
As of version 1.13
Add multiple cursors with Ctrl / Cmd + Click
VSCode
developers have introduced a new setting, editor.multiCursorModifier
, to change the modifier key for applying multiple cursors to Cmd + Click
on macOS and Ctrl + Click
on Windows and Linux. This lets users coming from other editors such as Sublime Text or Atom continue to use the keyboard modifier they are familiar with.
The setting can be set to:
ctrl/Cmd
- Maps to Ctrl on Windows and Cmd on macOS.alt
- The existing default Alt.There's also a new menu item Use Ctrl + Click
for Multi-Cursor
in the Selection
menu to quickly toggle this setting.
The Go To Definition and Open Link gestures will also respect this setting and adapt such that they do not conflict. For example, when the setting is ctrl/Cmd
, multiple cursors can be added with Ctrl / Cmd + Click
, and opening links or going to definition can be invoked with Alt +Click
.
With fixing Issue #2106, it is now possible to also remove a cursor by using the same gesture on top of an existing selection.
Upvotes: 199
Reputation: 391
As of Visual Studio Code version 0.10.9, you can now do a Create Multiple Cursors from Selected Lines by selecting multiple lines, and pressing Shift+Alt+I
Note: This is similar to Sublime Text's Ctrl+Shift+L functionality.
Source: https://code.visualstudio.com/updates/vJanuary#_thank-you
Relevant PR: https://github.com/Microsoft/vscode/pull/1479
Upvotes: 39
Reputation: 1219
Same issue on Ubuntu-MATE, but here you resolve it by:
gsettings set org.mate.Marco.general mouse-button-modifier "<Super>"
Upvotes: 4
Reputation: 1829
I had problem with ALT key, fix is to change alt+click
as a Gnome hotkey which clobbers multi-cursor select in VSCode, to super+click
by running:
gsettings set org.gnome.desktop.wm.preferences mouse-button-modifier "<Super>"
Source: http://2buntu.com/articles/1529/visual-studio-code-comes-to-linux/
Upvotes: 148
Reputation: 439
On Ubuntu, in order to enable multi-cursor clicking you will need to re-assign Alt+click first, by running the command below. This is because by default Ubuntu uses the shortcut itself and has it takes precedence.
> gsettings set org.gnome.desktop.wm.preferences mouse-button-modifier "<Super>"
Upvotes: 31
Reputation: 402
https://code.visualstudio.com/Updates
New version (Visual Studio 0.3.0) support more multi cursor feature.
Multi-cursor
Here's multi-cursor improvements that we've made.
⌘D selects the word at the cursor, or the next occurrence of the current selection.
⌘K ⌘D moves the last added cursor to next occurrence of the current selection.
The two actions pick up the matchCase and matchWholeWord settings of the find widget.
⌘U undoes the last cursor action, so if you added one cursor too many or made a mistake, press ⌘U to return to the previous cursor state.
Insert cursor above (⌥⌘↑) and insert cursor below (⌥⌘↓) now reveals the last added cursor, making it easier to work with multi-cursors spanning more than one screen height (i.e., working with 300 lines while only 80 fit in the screen).
And short cut of select multi cursor change into cmd + d(it's same as Sublime Text. lol)
We can expect that next version supports more convenient feature about multi cursor ;)
Upvotes: 9