Editing arbitrary regions requires cursor gymnastics or awkward mouse selection. Standard editors let you select text then act on it — Vim needs equivalent functionality.
Visual mode selects text ranges then applies operators. Three variants: character-wise, line-wise, and block-wise.
Entry commands:
| Key | Selection Type |
|---|---|
v | Character-wise (highlight characters) |
V | Line-wise (highlight entire lines) |
<C-v> | Block-wise (rectangular column selection) |
Post-selection operations:
J— join selected lines together<— indent left>— indent right=— auto-indent~— toggle case
For block selection across lines:
<C-v>start block- Move (
jjjor<C-d>or/patternor%) $go to end of linesA, type text,ESCto append to all lines
- Selection endpoint is marked at cursor position when entered
- Works with all operators:
d,y,c,gU,gu, etc. omoves cursor to opposite end of selectiongvreselects last visual selection
- Windows: may need
<C-q>instead of<C-v>for block mode - Block selection with
$selects to end of longest line - Visual mode is temporary — operators exit back to Normal
- Vim Modes — Visual is one of the three main modes
- Macros — Record actions on visual selection
- Block Selection — Special case of visual block mode
- Text Objects — Alternative selection syntax