vimtricks.wiki Concise Vim tricks, one at a time.

How do I edit multiple locations simultaneously like multiple cursors?

Answer

<C-n> to select (vim-visual-multi)

Explanation

vim-visual-multi provides VS Code-style multiple cursor support for Vim. Press <C-n> to add cursors at each occurrence of the word under cursor.

How it works

  • <C-n> selects the word under cursor and finds the next occurrence
  • <C-n> again adds a cursor at the next occurrence
  • All cursors edit simultaneously
  • q skips an occurrence, Q removes a cursor

Example

With the cursor on foo:

  1. <C-n> selects foo and highlights the next one
  2. <C-n> again adds a cursor at the next foo
  3. c changes all selected occurrences at once

Tips

  • Install: Plug 'mg979/vim-visual-multi'
  • <C-Down> adds a cursor on the line below
  • \\A selects all occurrences at once
  • Tab switches between cursor and extend mode
  • Many Vim experts prefer :s, macros, or . over multiple cursors

Next

How do you yank a single word into a named register?