Vim Multi-Cursor Editing: Complete Guide
Multi-cursor editing is one of the most powerful features in modern text editors, allowing developers to place multiple cursors across a file and edit text simultaneously. While Vim was originally designed as a modal single-cursor editor, modern Vim users have access to several robust multi-cursor workflows — both through built-in features and popular plugins. This guide covers everything you need to know to master multi-cursor editing in Vim and Neovim.
What Is Multi-Cursor Editing?
Multi-cursor editing is the ability to place more than one cursor in a buffer at the same time. Any keystroke you type is applied to every cursor simultaneously. This is particularly useful for renaming variables, adding prefixes or suffixes to multiple lines, transforming lists, and performing repetitive edits that don't quite justify a full substitution command.
In Vim, true multi-cursor behavior can be achieved in two main ways:
- Native Vim techniques — using the dot operator (
.), substitution (:s), global commands (:g), and visual block mode. - Plugins — such as
vim-visual-multi,vim-multiple-cursors, and Neovim'smini.surroundorNvim-cmp-adjacent tooling.
Why Multi-Cursor Editing Matters
Many developers coming from Sublime Text, VS Code, or JetBrains IDEs expect multi-cursor editing to be a first-class feature. While Vim's philosophy favors operator + motion over multiple cursors, there are real scenarios where multi-cursor editing is faster and more intuitive:
- Editing several occurrences of a word where a global substitution would be too aggressive.
- Adding the same text to the beginning or end of multiple non-contiguous lines.
- Transforming a column of data extracted from a CSV or log file.
- Refactoring variable names that appear in a specific visual region only.
Learning multi-cursor techniques also deepens your understanding of Vim's visual modes and command-line editing, making you a more effective editor overall.
Native Vim Techniques
Visual Block Mode
Visual block mode (Ctrl-v) is Vim's built-in answer to column editing. It lets you select a rectangular region and operate on every line within it. While not technically "multiple cursors," it achieves the same result for rectangular selections.
" Select a column from line 5 to line 10
5gg
Ctrl-v
10gg
" Insert text at the start of each selected line
I
const
" Append text at the end of each selected line
A
;
" Replace every character in the block with the same character
r
x
After pressing I or A and typing your text, press Esc to apply the change to every line in the block. This is one of the most reliable native workflows.
The Dot Operator
The dot operator repeats the last change. Combined with search (/) and n, it acts like a manual multi-cursor workflow where you walk through matches and apply the same edit.
" Search for 'foo'
/foo
" Change the word under the cursor to 'bar'
ciwbar
" Jump to next match and repeat the change
n
.
n
.
This approach gives you full control over which occurrences are changed, which is often safer than a blanket substitution.
Substitution and Global Commands
When you want to change every occurrence in a range, substitution is the canonical Vim way:
" Replace 'foo' with 'bar' on the current line
:s/foo/bar/g
" Replace 'foo' with 'bar' in the entire file
:%s/foo/bar/g
" Replace 'foo' with 'bar' in the current visual selection
:'<,'>s/foo/bar/g
" Replace 'foo' with 'bar' on every line containing 'TODO'
:g/TODO/s/foo/bar/g
For confirmations, add the c flag to walk through each match interactively:
:%s/foo/bar/gc
Using Plugins for True Multi-Cursor Editing
vim-visual-multi
vim-visual-multi is currently the most popular and actively maintained multi-cursor plugin for Vim and Neovim. It provides Sublime-Text-like behavior with a rich set of mappings.
Install it with your plugin manager:
" vim-plug
Plug 'mg979/vim-visual-multi'
" packer.nvim (Neovim)
use { 'mg979/vim-visual-multi' }
Key mappings provided by the plugin:
" Add a cursor under the current word
Ctrl-n
" Add the next match of the current word as a cursor
Ctrl-n (again)
" Skip the current match and move to the next
Ctrl-x
>" Select all matches of the current word
Ctrl-Shift-n " or \\A in some configurations
" Add a cursor at any position (manual mode)
Ctrl-Down " add cursor below
Ctrl-Up " add cursor above
" Remove the current cursor
q
" Exit multi-cursor mode
Esc
A typical workflow looks like this:
" 1. Place the cursor on a variable name
" 2. Press Ctrl-n to select the word
" 3. Press Ctrl-n again to add the next occurrence
" 4. Repeat until all desired occurrences are selected
" 5. Press c to change them all at once
ciwnewName
" 6. Press Esc to finalize
vim-multiple-cursors
vim-multiple-cursors is an older alternative with a simpler interface. It mimics Sublime Text's Ctrl-d behavior closely.
" vim-plug
Plug 'terryma/vim-multiple-cursors'
Default mappings:
" Select the next occurrence of the current word
Ctrl-d
>" Skip the current occurrence
Ctrl-k
>" Select all occurrences
Ctrl-a
>" Exit multi-cursor mode
Esc
While simpler, this plugin is no longer actively maintained and can conflict with other mappings. For new setups, vim-visual-multi is generally recommended.
Neovim-Specific Options
Neovim users can take advantage of Lua-based plugins that offer multi-cursor-like functionality. The mini.surround and mini.operators modules from mini.nvim provide surround editing that complements multi-cursor workflows. Additionally, Nvim-cmp and LuaSnip users can use snippet nodes to apply synchronized edits across multiple placeholders.
-- packer.nvim
use { 'echasnovski/mini.nvim', branch = 'stable' }
-- Example setup for mini.surround
require('mini.surround').setup({
mappings = {
add = 'sa',
delete = 'sd',
find = 'sf',
highlight = 'sh',
replace = 'sr',
},
})
Best Practices
- Prefer native Vim commands when possible. Substitution and the dot operator are often faster and more predictable than multi-cursor plugins, especially for global changes.
- Use multi-cursor for visual, non-global edits. When you need to change occurrences only within a visible region or skip specific matches, multi-cursor shines.
- Learn visual block mode first. It is built-in, reliable, and covers many column-editing scenarios without any plugin.
- Avoid over-reliance on plugins. Multi-cursor plugins can mask a lack of familiarity with Vim's native editing model. Use them as a supplement, not a crutch.
- Check for mapping conflicts. Plugins like
vim-visual-multiuseCtrl-nandCtrl-d, which may conflict with completion plugins or terminal shortcuts. Review and remap as needed. - Practice the escape habit. Always press
Escto finalize multi-cursor edits; otherwise, you may end up with partial changes or stuck in insert mode across multiple cursors. - Combine with macros for complex edits. When multi-cursor alone isn't enough, record a macro with
qand replay it with@for powerful repetitive transformations.
Common Pitfalls
- Forgetting to press Esc after insert operations in visual block mode. The change only applies to all lines when you exit insert mode.
- Using multi-cursor when substitution would be simpler. If every occurrence needs the same change,
:sis more reliable and reviewable. - Selecting too many cursors. Performance can degrade with hundreds of cursors. For large-scale changes, prefer substitution or macros.
- Confusing plugin default mappings. Always read the plugin documentation and configure mappings to match your muscle memory.
Conclusion
Multi-cursor editing in Vim is a versatile skill that bridges the gap between Vim's modal editing philosophy and the multi-cursor workflows popularized by modern editors. By mastering native techniques like visual block mode, the dot operator, and substitution, you can handle the majority of repetitive editing tasks without any plugins. When you need true Sublime-Text-style multi-cursor behavior, vim-visual-multi provides a robust and well-maintained solution. The key is to understand when each tool is appropriate — reach for substitution when changes are global, use the dot operator for selective repetition, employ visual block mode for column edits, and reserve multi-cursor plugins for complex, non-uniform edits across scattered locations. With practice, these techniques become second nature and dramatically improve your editing speed and precision.