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

How do I append text at the end of multiple lines using visual block?

Answer

<C-v>jj$A

Explanation

Combining visual block mode with $ and A lets you append text at the end of multiple lines, even when the lines have different lengths.

How it works

  1. Press <C-v> to enter block mode
  2. Select lines with j
  3. Press $ to extend to end of each line
  4. Press A to append
  5. Type text and press <Esc>

Example

alpha
bravo
charlie

Select all lines with <C-v>2j$, press A, type ;, press <Esc>:

alpha;
bravo;
charlie;

Tips

  • Without $, the block only extends to the shortest line length
  • $ makes the block extend to the end of each line individually
  • This is the standard way to add semicolons or commas to multiple lines
  • Also works for adding trailing comments

Next

How do you yank a single word into a named register?