How to select a column in Vim with Visual Block mode
Press Ctrl-v to start Visual Block mode and extend the block with j and l, then press I, type, and press Esc: the text appears on every line. $A appends to the end of every line instead.
Export them, then end them
Every line needs export in front: Ctrl-v, 2j down to the last line, I, type export once and press Esc. Then a semicolon at the end of each, though the lines are different lengths: Ctrl-v, 2j, $, A, ;, Esc.
This editor needs a keyboard. Read on, and play it at your computer.
| Keys | What it does |
|---|---|
| Ctrl-v | Start Visual Block mode: a rectangle, from the cursor. |
| j k / l w | Make the block taller / wider. |
| $ | Stretch the block to the end of every line, however long each one is. |
| I, text, Esc | Insert the text in front of the block, on every line. |
| A, text, Esc | Append the text after the block, on every line. |
| $A, text, Esc | Append to the end of every line. |
| c, text, Esc | Replace the block with the text on every line. |
| r and a character | Fill the whole block with that character. |
| d or x | Delete the block (a column of text). |
| o / O | Jump to the opposite corner / the other corner on the same line. |
The Esc does the work
While you type after I or A, the text appears on the first line only, and it can look as though the block did nothing. It's the Esc that copies it to every other line of the block. So: block first, then I or A, then type, then Esc.
This is how you comment out lines by hand (Ctrl-v, down, I, // , Esc), add a prefix to a list, or turn a column of words into a column of strings. It needs the text to line up: a block is a rectangle, so it works on columns, not on words that move around from line to line.
Without a block
When the lines don't line up, :normal runs Normal-mode keys on every line of a range instead. Select the lines with V, press :, and type normal A; to append a semicolon to each, or normal I// to comment them out, then ↵. With % in place of the selection, :%normal A; does every line in the file.