How do I append text to the end of multiple lines with different lengths in visual block mode?
Answer
<C-v>{motion}$A
Explanation
In visual block mode, pressing $ makes the right edge of the selection "ragged" — it extends to the real end of each line regardless of length. Following up with A then appends at the true end of every selected line simultaneously. This is the fastest way to add trailing characters (semicolons, commas, quotes) to a group of lines that don't share a common column width.
How it works
<C-v>enters Visual Block mode.{motion}(e.g.,3j) extends the block downward over the target lines.$changes the right edge from a fixed column to "end of line" for each individual line. The block now appears ragged on the right.Aenters Insert mode positioned after the last character on each selected line.- Type your text, then press
<Esc>— Vim replays the insertion on every line in the block.
Example
Starting with:
const x = 1
const longName = 2
const ab = 3
Press <C-v>2j$A;<Esc> to produce:
const x = 1;
const longName = 2;
const ab = 3;
Tips
- Use
Iinstead ofAto insert at the start of the block column (not end-of-line) — useful for prepending//or-to each line. - The
$selection persists for subsequent operations: you can alsodto delete to end-of-line across all selected lines, orcto change. - If lines are already uniform width, you don't need
$— any column position works withA.