Barbarian Meets Coding


Boost Your Coding Fu With VSCode and Vim
Chapter 18.Table of ContentsCheatsheet

Multiple Cursors

If you’re a hardcore Visual Studio Code user, chances are you use multiple cursors. VSCodeVim supports multiple cursors in Normal mode experimentally. That is, you can spawn multiple cursors and then use Normal mode operators to unleash the power of Vim in multiple locations at once.

If you want to add multiple cursors based on word search you need to:

  1. Move the cursor on top of a word in your code
  2. Type <CMD-D> (CTRL-D on Windows/Linux) or gb to add another cursor. This puts Vim into Visual mode and ready to operate on the word you have selected
  3. Type <CMD-D> (CTRL-D on Windows/Linux) or gb to continue adding cursors until you’re done
  4. Now you can perform an action in Visual mode (delete, change, etc) or,
  5. Go back to Normal mode with <ESC> and type any Normal mode command keeping the multiple cursors

If you want to extend your cursors up or down in consecutive lines, then the best approach is to rely in Visual-block mode like this:

  1. <CTRL-V> to change to Visual-block mode
  2. j, k to select a rectangle of text downwards or upwards respectively
  3. I to insert or A to append, insert text and <ESC>
  4. Alternatively, use any normal mode commands to operate on the selected text in each line

Jaime González García

Written by Jaime González García , Dad, Husband, Front-end software engineer, UX designer, amateur pixel artist, tinkerer and master of the arcane arts. You should follow him on Twitter where he shares useful stuff! (and is funny too).Jaime González García