Visual mode is how you see exactly what an operation will affect, and blockwise mode edits columns.
Visual mode lets you select text first and then act on it. There are three kinds:
vcharacterwise,Vlinewise,Ctrl-vblockwise (a rectangle).
Extend the selection with any motion or text object (vip selects a paragraph, vi" a string), press o to jump to the other end of the selection, and gv to reselect the last selection. Then apply an operator: d, y, c, >, <, ~ (toggle case), u/U (lower/upper), J (join), or : to run an Ex command on the selected lines (Vim fills in :'<,'>).
Block mode is the multi-cursor of Vim. Select a column with Ctrl-v and j, then:
ItextEscinserts the text at the start of the block on every line.AtextEscappends after the block; with$first, it appends at the end of each line even if lines differ in length.creplaces the block on every line,rreplaces every selected character.
The text appears on all lines only after you press Esc.
Visual mode is great while learning and for irregular selections, but for repeatable work prefer operator + text object (dap rather than vapd): Visual selections repeat with . by size, not by structure.
Example
Vjjd " select 3 lines linewise and delete them
vi"y " yank a string's contents
gv " reselect the previous selection
Vip> " indent the whole paragraph
" comment out 4 lines with a block insert:
Ctrl-v 3j " select a column over 4 lines
I# <Esc> " '# ' inserted on every line
" append ';' to lines of different lengths:
Ctrl-v 3j $ A;<Esc>Remember
- v characters, V lines, Ctrl-v rectangular blocks
- Block I/A insert on every line, shown after Esc
- gv reselects; o jumps to the other end of the selection
Watch out for
- Expecting the block insert to appear while typing; it is applied to the other lines only when you press Esc.