1031

Is it possible to enable multiline editing like in Sublime Text?

For example, press Ctrl to place additional cursor carets and being able to write/delete on multiple places in the document at one time.

7
  • 8
    In many mac apps (e.g. TextEdit) I can also Option-drag the mouse to select a box. Is this available in VS Code? Commented Apr 5, 2017 at 4:15
  • 7
    From April 2018 (version 1.23), we can use middle mouse button to select multiple columns. code.visualstudio.com/updates/… Commented May 28, 2018 at 3:19
  • 14
    For anyone looking for the name of this command in the keyboard shortcuts section, it's: editor.action.insertCursorAtEndOfEachLineSelected Commented May 13, 2019 at 10:54
  • 1
    @enzoborgfrantz +1 Exactly what I was looking for! The selected answer should have first mentioned the relevant editor commands because the keybindings can vary. Commented Aug 1, 2019 at 7:25
  • 5
    Mac: OPTION + SHIFT + I adds a cursor to the end of every line in the selected/highlighted text. Much faster than adding an individual cursor to every line if you have a lot of lines Commented Oct 14, 2022 at 14:16

35 Answers 35

1829

On Windows, you hold Ctrl+Alt while pressing the up or down arrow keys to add cursors.

Mac: ⌥ Opt+⌘ Cmd+/

Linux: Shift+Alt+/

Note that third-party software may interfere with these shortcuts, preventing them from working as intended (particularly Intel's HD Graphics software on Windows; see comments for more details).

If you experience this issue, you can either disable the Intel/other software hotkeys, or modify the VS Code shortcuts (described below).

Press Esc to reset to a single cursor.

Multiline cursors in Visual Studio Code

Or, as Isidor Nikolic points out, you can hold Alt and left click to place cursors arbitrarily.

Arbitrarily placed multiline cursors in Visual Studio Code

You can view and edit keyboard shortcuts via:

File → Preferences → Keyboard Shortcuts

Documentation:

https://code.visualstudio.com/docs/customization/keybindings

Official VS Code Keyboard shortcut cheat sheets:

https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf
https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf
https://code.visualstudio.com/shortcuts/keyboard-shortcuts-linux.pdf

Sign up to request clarification or add additional context in comments.

32 Comments

On windows, the first option just flips my screen. :-/
This is not valid any more. Try CTRL + SHIFT + UP/DOWN/CLICK OR ALT + SHIFT + UP/DOWN/CLICK
@Nacimota - on a windows 10 machine (just tested now) the combination CTRL+ALT+ARROW will flip the screen, CTRL+ALT+SHIFT+ARROW will create a new cursor. The published list of keyboard shortcuts PDF may be out of date.
@AlexC the shortcuts are not out of date; download the latest build and look at the configuration yourself. If you're finding that the shortcuts listed are flipping your screen, I'd wager it's because you have an Intel GPU and are running the Intel software for it which intercepts these shortcuts by default. Open the HD Graphics software and disable or rebind hotkeys if it bothers you, but do not edit my post to add incorrect information. The shortcuts listed are accurate, and I am not going to list every piece of 3rd party software that may or may not interfere with them.
@Nacimota with all due respect, it was an honest mistake which represents reality for a significant portion of users. There are enough intel machines out there where this might be a default configuration that the additional information was valuable. We both have the goal of providing the best most up to date answer. An additional sentence to enumerate that difference would be helpful.
|
263

Solved using just two steps!

  1. Ctrl + F

  2. Alt + Enter

It's equal to Sublime Text's Alt + F3.


Note: For macOS, + F followed by + Enter is equivalent to Sublime Text's + + G.

Enter image description here

8 Comments

The same effect gives you hitting ctrl+F2
Can we select all lines at a time containing that keyword ? Sublime text had it Ctrl + F > Alt + F3 > Ctrl + L
What is this in Mac terms? Ctrl and Alt replaced by...?
This is easy and should have been accepted answer
Nice! Thank you. It was not covered in the starter docs.
|
122

You can just Alt + click for additional cursors. And as already mentioned, Ctrl + Alt + or .

5 Comments

And you can use Alt+Shift+click to select two lines and every line in between.
Question is, how to edit its Key Binding (What is Alt + Click 's name?)
Alt + click automatically defines the word, or moves to the left of the word and does not work for me.
Found the answer to my question, it can either be Alt (which is default, or Ctrl / ⌘. This option can be modified with the "editor.multiCursorModifier": "ctrlCmd" key in settings.json.
If you open the UI settings and search for "multi cursor" the options for this should pop right up
103

Box Selecting

Windows: shift + alt + Mouse Left Button

macOS: shift + option + Click

This is contrary to what is mentioned in an answer to Does Visual Studio Code have box select/multi-line edit?.

1 Comment

I'm not a fan of Shift+Alt+Click (although it works). So to make it work (on Windows) just like in VS, I did this: go to Selection menu, and select Switch to Alt+Click for Multi-Cursor. Now Alt+Click does box selecting.
80

I wanted to select multiple lines and hit "something" to have a cursor for each select lines (similar to Ctrl + Shift + L in Sublime Text). This action in Visual Studio Code is called "Add Cursors to Line Ends".

This was tested in Visual Studio Code 1.77.0 (April 2023) and works on both Windows and Mac.

Here is the way:

  1. Select the lines you want to have multiple cursors.
  2. Simply hit Alt + Shift-I.

You now have one cursor per selected line.

4 Comments

@Manza In VS Code, you it's ALT-SHIFT-I (like i not L). The font doesn't help to see correctly. I use this command multiple times per day on both Mac and Windows and just tested once again with the latest version of VS Code : 1.24.1 and I assure you it works. Maybe you have a plugin causing conflict ?
wow yeah, that do the trick, thank you so much, i was still flipping between sublime becuase of this feature, is the soooo handy
for me it's CTRL-SHIFT-L (windows)
This is what I was looking for, you can modify it in vs studio settings looking for the "add cursors to line ends" keybindings.
48

Use Ctrl + D to use multi word edit of same words in Windows and Linux.

Use CMD + D for Mac.

2 Comments

As @Krishnaraj said, Ctrl + D work. Actually both VSCode and Sublime support this. Make sure apply Ctrl + D on all later occurrence without releasing ctrl. Yeah, you still need manually select, it just help you free your mouse. MacOS Command + D
And note: Ctrl + D only works for 'Next selection', 'Previous selection' is only accessible via Ctrl + P and then typying: '>Add Selection To Previous Find Match' (of a part of that text!)
36

In the latest release of Visual Studio Code, you can now drag the cursor while holding Option (Alt on Windows) to select the same column on multiple rows.

To enable this, make sure you change your editor.multiCursorModifier to look like this:

"editor.multiCursorModifier": "ctrlCmd"

From the Visual Studio Code release notes 1.32.0:

In the following video, the selection begins as a regular selection and then Alt is pressed and held until the mouse button is released:

Example of improved column selection:

4 Comments

Thank you, this works. It's funny though how "alt" does not work, by contrast "ctrlCmd" actually makes it work with the ALT-key. head explodes
@tyler-becks how did you make this GIF?
@bvdb I think what's happening is that having Alt as the multi cursor modifier is preventing it working with a drag to do a box select
how to open settings JSON in VSC to complete the answer: stackoverflow.com/questions/65908987/…
31

From the version 1.13 (May 2017) you can finally change the default modifier key for creating multiple cursors (add to settings):

"editor.multiCursorModifier": "ctrlCmd"

P.S.: The modifier "follow link" from this moment will be Alt.

1 Comment

A lot of these other answers are not addressing the question. This one is - how to place extra carets with mouse clicks.
27

Step 1:

Select the word to be replaced.


Step 2:

Use Ctrl + F to select its multiple occurrences.


Step 3:

Use Alt + Enter to set cursor at all the found occurrences.


Step 4:

Just start typing the new word.


Alternatively on Mac:

⌥ Opt + Click to set cursor on the click location.

2 Comments

Also cmd+shift+L on Mac. Does the same thing in one step.
@Andres Thanks! This did solve my issue at Windows, the other solutions flip my screen.
24

On Mac it is:

Option + Command while pressing the up or down arrow keys.

Comments

21

I am using the vscodevim extension, so I'm not sure if this is a common problem. But, I was having the issue where Ctrl + Alt + UpArrow flipped my screen upside down.

Looking at the Visual Studio Code Basics (I don't know if they changed this in a recent update), it says to use:

Ctrl + Alt + Shift + (Up/down)

1 Comment

Ctrl + Alt + [Arrow Key] is a common keyboard shortcut for screen rotation, certainly with Intel graphics drivers and / or associated software. I imagine it is being intercepted by this before VSCode gets a look in. Recently (and annoyingly, since I used to use it) rotation seems to have been discontinued in an update to the Intel software and is now only available through long-winded menus in Windows. The keyboard shortcut should therefore work in VSCode with more recent drivers.
17

(Windows 10 pro x64) Here have some ways!

  1. Alt + click

  2. Alt + Ctrl + up/down

  3. Keybindings: Ctrl + click (??? it doesn't work!)

Enter image description here

1 Comment

17

Working solution for me was first selecting the required text to edit and then using CTRL + F2 to select all matching data in the page. You may also use CTRL+Shift+L as suggested by @lesterCovax

Please Note: The above solution uses the inherent ability of VSCode editor to select similar text across the entire page, and therefore, be careful.

For me the above solution of Ctrl + ALT + Arrowkeys did not work as it caused the screen to change its display orientation against selecting the lines in VSCode.

enter image description here

Comments

14
  • To add multiple cursors at any text position This is done by using Ctrl+Click. Firstly you have to enable Multiple-Cursor Modifier. Simply type this option on Command Palette by Ctrl+Shift+P to enable it.

  • To remove a cursor form multiple text position. Do Ctrl+Click on the cursor.

Comments

13

version 1.43 (February 2020)

You can now toggle column selection mode, which changes mouse gestures and arrow keys, via:

  • Menu Bar > Selection > Column Selection Mode
  • Ctrl+Shift+P (Show All Commands) > Toggle Column Selection Mode
  • Bind your key for command "editor.action.toggleColumnSelection"

enter image description here

Note: There is a "Column Selection" panel in the status bar after activation, which you can press to disable it again.

Comments

11

As of April 2018 (version 1.23) you can now also use the middle mouse button to multiline select / box select.

2 Comments

Thanks for that, it is a time save are there an option for key board? like highlight and then ctrl + l in sublime?
That's a slightly different feature, but you're probably looking for ctrl+ i. code.visualstudio.com/docs/getstarted/keybindings
10

In addition to all of the answers, there is one more way. Select the lines you want and then press:

  • Windows: Shift + Alt + i
  • Mac: shift + option + i

This puts a cursor in every row in the selection.

1 Comment

How to make the same, but place the cursors in the beginning of the lines?
9

According to VS Code 1.55.2 version(2021) under User > Commonly Used section there is an option as Multi Cursor Modifier. See below image. enter image description here

for multi cursor default key is alt if you want it can change to Ctrl. Moreover, for suitable places, you can hold the Middle Mouse button and move to down.

Comments

8

In Windows, the below combinations work for me:

  • Ctrl + Shift + Alt + down arrow
  • Ctrl + Shift + Alt + up arrow

1 Comment

This appears to be identical to Visual Studio!
8

I am using the latest version of VS code i.e., 1.46.1 (May 2020) in Windows 10. Just press Alt+mouse left click on the lines you want to select. This will let you select multiple lines at once and let you edit them. Also Press Esc to exit from it. This is really helpful if you're coming from sublime text.

Update 1 - above mentioned solution is still valid with Windows11 (April 2024).

Suppose you're on a certain line number and want to select lines below and above, to do this simply press Ctrl + Alt + Up or Down arrow.

If you want to select either above lines or below lines then with above key combination use Shift also.

Comments

6

In Visual Studio Code just press Alt and place your cursor to the edit place(where you want to edit) and right click to select.

1 Comment

This answer seems incomplete
6

(NO MOUSE) For macOS, I found this to be very quick!

  1. CMD + f To search the (word) you want to change.
  2. Option + Enter To select all word you search for.

Just update the first word and it will update all the selected.

Comments

6

I think it depends on your Visual Studio Code version.

Mine is Linux version Visual Studio Code 1.7.2.

{ "key": "ctrl+shift+up",         "command": "editor.action.insertCursorAbove",
                                     "when": "editorTextFocus" },
{ "key": "shift+alt+up",          "command": "editor.action.insertCursorAbove",
                                     "when": "editorTextFocus" },
{ "key": "ctrl+shift+down",       "command": "editor.action.insertCursorBelow",
                                     "when": "editorTextFocus" },
{ "key": "shift+alt+down",        "command": "editor.action.insertCursorBelow",
                                     "when": "editorTextFocus" }

The point is the shortcuts are not same in all machines, so you should check your configuration. Go to menu:

Menu FilePreferencesKeyboard Shortcuts

Search for editor.action.insertCursorAbove and editor.action.insertCursorBelow and see your current configurations. You may change them if they conflict with operating system's shortcut keys.

1 Comment

Adding the SHIFT + ALT + UP/DOWN to my user settings worked on Windows 10
5

Well, I used the Alt key to select the lines where I wanted to edit, and that's it. Alternatively, we can use the Ctrl + Alt + UP/DOWN arrow if the things to be edited are above or below.

Comments

4

If you're using Linux, there's a possibility of a conflict with Alt + click, which is the default for "moving a window".

You can go to menu SettingsWindow BehaviorWindow BehaviorActions tab

Just remove Alt + left (hold) and it will work.

This is the best way, because you don't need to hold two + keys to do such a simple task.

Comments

4

On windows, you can create additional cursor on the next/previous lines by pressing:

Ctrl + Alt + Shift +Down/Up

Missing the Shift will flip your screen.

Creating additional cursors will allow you to edit multiple lines at once.

Comments

4

For the latest Mac Users in VS code:

option + command + up/down for multiselect.

Ctrl + E for going to end of the line, Ctrl + shift + E for going to end of the line with selection.

Comments

3

Just Opt + click works for me on Mac

Comments

3

My settings: Windows 8.1 64 bits, Visual Studio Code version 1.33.1.

Problem: Conflict with keyboard shortcuts of Intel HD Graphics 4000

I had a problem when I was using the default shortcuts of the Visual Studio Code (Ctrl + Alt + UP, Ctrl + Alt + DOWN). In my case, these commands were turning my screen in 0º and 180º respectively. It's happening, because there is the Graphic Intel application installed on my computer. Then, I just disable the shortcuts of this application.

Here is an tutorial to help someone.

2 Comments

In Windows 7 you can right click the desktop, select graphics options -> hotkeys -> disable.
Yes!!! This was the answer for me too, the other suggestions didn't work and the accepted answer flipped my window upside down.
3

I am using the Sublime Text keymap and the keybinding provided by the top answer did not seem to work :( Could be some conflicts between Visual Studio Code and sublime keymaps.

The keybinding recommended by @Han works for me (much appreciated!):

  • Enter multiline cursor mode with Ctrl + Shift + Up/Down
  • Exit with Esc

(Sidenote) Below is a small example of using Emmet together with the multiline cursor (enabled and disabled with these key bindings listed above):

Enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.