level 06

Visual Mode

Select by character, line, and block, then act on the selection.

Visual mode is Vim with training wheels you never have to take off. Select first, see exactly what you’ve got highlighted, then hit an operator. For most edits a text object is faster (no selecting, just ci"), but some jobs are far clearer when you can see the range. And one of them, editing in columns with Visual block, has no real equivalent anywhere else.

Entering Visual Mode

v       → character-wise
V       → line-wise
Ctrl+v  → block-wise (column selection)
gv      → re-select the last selection

Operators on a Selection

d  c  y      → delete / change / yank
>  <  =      → indent / de-indent / auto-indent
~  u  U      → toggle / lower / upper case

Visual Block (Ctrl+v)

The unique one: select a rectangular region. To add text to the start of many lines — Ctrl+v, select down with j, press I, type your text, press Esc, and it applies to every line. Invaluable for prefixes, columns, and aligned data.

Character-wise selection

  1. On quick, press v, then e to select the word; press e again to extend.
  2. Press Esc to cancel.
  3. On q of quick, press ve to select, then d to delete; undo with u.
  4. Select brown fox with v + motion and press ~ to toggle case.
normalpress i to type · hjkl to move

goal v plus a motion selects a region; operators act on it.

Line-wise selection

  1. On the for line, press V, then j three times to select the block.
  2. Press > to indent it one level.
  3. Press gv to reselect, then < to un-indent.
  4. Select the two const-style lines and press d; undo.
normalpress i to type · hjkl to move

goal V selects whole lines; > and < indent the block.

Visual block — add a prefix

  1. Press Ctrl+v to enter Visual block.
  2. Press G to extend the cursor down every line.
  3. Press I, type - (dash space).
  4. Press Esc — every line now starts with - .
normalpress i to type · hjkl to move

goal Apply the same text to the start of many lines at once.

Visual block — delete a column

  1. Put the cursor on the | at the start of the first line.
  2. Press Ctrl+v, then j three times to extend down.
  3. Press l until the first column is fully selected.
  4. Press d to delete the column.
normalpress i to type · hjkl to move

goal Block mode removes a rectangular region.

Visual block — append to line ends

  1. Press Ctrl+v, then G to select down.
  2. Press $ to extend the selection to each line’s end.
  3. Press A, type ;, press Esc — every line now ends with ;.
normalpress i to type · hjkl to move

goal $ extends the block to each line's end before A.

Capstone — turn raw rows into a typed enum

Convert this flat list into a block of object entries — RED: "red", and so on — using Visual mode for every step instead of editing line by line:

  1. Block prefix. Ctrl+v, G, then I and two spaces, Esc — indent all five.
  2. Block suffix, part one. Ctrl+v, G, $, then A, type : "", Esc — every line now ends with : "".
  3. Fill the value with a lowercased copy of the key. On line 1: 0w to reach the key, yiw to yank it. Press f" to land on the opening quote, a, then Ctrl+r 0 to paste the key between the quotes, Esc. Lowercase it in place with viwu. That precise little routine is a perfect macro — record it with qa … q and replay 4@a down the rest.
  4. Trailing commas. Ctrl+v, G, $, A, type ,, Esc.
  5. Reselect any line range with V and press = to tidy the indentation.
normalpress i to type · hjkl to move

goal Chain character-wise, line-wise, and block edits into one transform.