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

How do I append text to the end of multiple lines that have different lengths?

Answer

<C-v>jj$A;

Explanation

Visual block mode normally selects a fixed-width column, which makes appending tricky when lines have different lengths. The key insight is using $ after entering visual block mode — this extends the selection to the end of each line regardless of length. Then A enters insert mode after the last character on every selected line, and whatever you type appears at the end of all of them.

How it works

  • <C-v> — enters visual block mode
  • jj (or any vertical motion) — selects multiple lines
  • $ — extends the selection to the end of each line, even if they differ in length
  • A — appends after the selection on every line
  • Type your text (e.g., ;), then press <Esc> — the text appears at the end of all selected lines

Example

Before:              After:
let x = 1            let x = 1;
let name = "foo"     let name = "foo";
let y = 42           let y = 42;

The ; is appended to the end of each line, regardless of how long they are.

Tips

  • Without $, visual block mode selects a fixed column — A would then insert at that column position, not the end
  • Use I instead of A to insert at the beginning of the block selection
  • This technique works for appending any text: commas, closing brackets, comments, etc.
  • Combine with gg and G to select all lines: <C-v>gg$A or <C-v>G$A

Next

How do I return to normal mode from absolutely any mode in Vim?