DEV Community

Sergiu Mureşan
Sergiu Mureşan

Posted on

Vs Code Multiple Cursors Multi-cursor in Visual Studio Code

Multi-cursor is one of those features that impresses many non-programmers but, in our world, this is quite an old one. Many people know about this but I think they are not using it to its full potential. So here is what you can do with multi-cursor:

1) Add multi-cursor below/above (CTRL+ALT+/)

This is a simple functionality but it's hidden by its strange shortcut that also turns your screen upside-down. I always re-bind this functionality to CTRL+SHIFT+/ so it's the same with Visual Studio.

Example video:

2) Add multi-cursor to next occurrence (CTRL+D)

Simply select a piece of text, and when you use this shortcut it will add another cursor to the next occurrence of the selected text, after that, you can edit both at once. This will help you edit code real fast.

Example video:

3) Add multi-cursor to all occurrences (CTRL+SHIFT+L)

Same mechanism as above but instead of just adding a cursor to the next occurrence it adds it to all the occurrences in the current file. This can be a really quick and flexible find and replace.

Example video:

4) Undo last cursor operation (CTRL+U)

This one I didn't know about for a long time. It's simple and straightforward. If you accidentally add too many cursors you can undo that operation using this shortcut. It will help you from the hassle of going aaaallll the way back and re-selecting only the occurrences you need.

Example video:

And that's it! They are fairly simple and straightforward features that you can 100% customize their key binding.

I hope this helped you, I know it helped me!

  • What features do you think are worth checking out next?
  • Do you know anything I missed relating this feature?

Top comments (7)

Collapse
 
yechielk profile image
Yechiel Kalmenson

Wow, thanks for these, they will definitely come in handy!

And yeah, multi-cursor is one of those things that after I started programming I couldn't figure out why none of the word processors adopted...

Collapse
 
giancarlorocha profile image
Giancarlo Rocha

hey man, thats a good serie. for the next ones you could put shortcuts for copy line, delete line, move lines up and down and ident lines back and forward. That ones also help me a lot

Collapse
 
codevault profile image
Sergiu Mureşan

Haven't thought about those yet, but I also use them quite a bit, I will create a post about them in a later part of the series for sure. Thanks for the suggestion!

Collapse
 
enriquemorenotent profile image
Enrique Moreno Tent

CTRL + SHIFT + L

I did not know that one! What I did is press CTRL + D and keep it pressed for a couple seconds :D

Collapse
 
codevault profile image
Sergiu Mureşan

I was doing the exact same thing before I learned about it. It's the best when you are working with large source files.

Collapse
 
keef profile image
keef

wish Sublime would have this :(

Collapse
 
callumgilly profile image
Callum Gilchrist

Alt click will also add another cursor :)