VSCode Multiple Cursors Support for Advance Editing

VS Code Multi Cursor Feature
VS Code Multi Cursor Feature. Image for depiction only.

Visual Studio Code is an opensource Code Editor by Microsoft also known as VS Code. It support all major platforms including Windows, Linux and macOS and is even available as web app through vscode.dev. VSCode is now one of the most used Source Code Editor, its lite weight, fast and comes with host of features.

One such feature is multiple cursor editing. Think it as improved version of Column-mode editing where you can work with multiple cursor in single editor view. When you have multiple cursor in one view, any operation, editing you do will be applied at all the cursor position. In VS Code, there are multiple ways to activate multi-cursor feature.

Alt + Mouse Click

This is one of the most simplest way to add multiple cursors in Editor View. All you have to do is click with mouse anywhere to place your first cursor there, now hold your alt key ( option key on Mac) and now click with mouse wherever you want more cursors to appear. Once you have multiple cursors in place, you may now carry out the operation you may want to do. When done, clicking anywhere on the Editor without holding alt key will result in removal of all other cursors.

Ctrl + d (Command + d)

This key combination ( ctrl+d ) is one of my favorite, it lets you place cursors on all similar words or string in the editor. All you need to do is first place cursor on desired keyword or string in your editor, then press ctrl + d repetitively and VS Code will try to find next occurrence of that keyword and will place cursor on them. Sometimes, it may not find what exactly you are looking but it gets the job done pretty fast most of the time.

Ctrl + d (Command + d) with find and replace

It is same as regular ctrl + d but in this one you can actually find and replace the word or keyword. First highlight the word using mouse or keyboard, then press ctrl + d repetitively until all the occurrence of that word has cursors on it. Now you can type anything and it will replace that word. Press esc when you are done.

Column Edit mode

This is the classic multiple cursors mode, this is useful when you are working with tabular data like editing CSV records. It lets you have multiple cursor up and down and then do your operation. To do this, simply press and hold ctrl + alt , then use up / down arrows key to place new cursors in either direction.

Column Edit with mouse drag

Another quick and easy method to activate multiple cursors is to press and hold shift + alt and then drag with mouse while holding mouse button. You can drag up or down , once there are multiple cursor, you need to press right or left arrow key on keyboard in order to not to replace the selection. Little hit and trial will give you better idea.

Find all ( Ctrl + Shift + L )

Another useful combination of keys for multiple cursors is ctrl + shift + L which lets you place multiple cursors at all the occurrence of the given keyword or word in the Editor. To do this, first select the word for which you want to look for, now press ctrl + shift + L , here VS Code will not only find that word but will also place cursor on its each occurrence.

Other multi-cursor operations

Other than above, you may carry out few more operation, some with combination of other keys with above mentioned methods. For example, if you want to place multiple cursors on beginning or end of certain lines then if there is a common keyword on those lines, select it and press ctrl + shift+ L, it will place cursor on those words, now press end on keyboard to move cursors to the end of line or press home to move all cursors at start of line.

ctrl + u : You can use ctrl + u to undo last multi cursor selection. Think it as undo but only for multi-cursor mode. For example, you were using ctrl + d , and placed cursor on wrong position, instead of starting all-over, just press ctrl + u and it will remove cursor from immediate last position. Though its most useful when you are doing alt+ mouseclick.

Finally, its up to you that how to utilize such features. One should give some time and play with the above methods to get better idea of it. I hope, reading this article will help you to make it more fun and speed up coding with VS Code. If you have suggestion or correction then please feel free to reply in comments.


No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *