vimtricks.wiki Concise Vim tricks, one at a time.

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.
  • A enters 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 I instead of A to 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 also d to delete to end-of-line across all selected lines, or c to change.
  • If lines are already uniform width, you don't need $ — any column position works with A.

Next

How do I rename a variable across all its case variants (camelCase, snake_case, SCREAMING_CASE) in one command?