How do I append text to the end of multiple lines at once using visual block mode?
Answer
<C-v>jj$A text<Esc>
Explanation
Visual block mode combined with $A lets you append text to the end of multiple lines simultaneously, even when those lines have different lengths. This is one of the most satisfying tricks in Vim and a huge time-saver for bulk edits.
How it works
<C-v>enters visual block modejj(or any vertical motion) extends the selection down to cover the desired lines$extends the block selection to the end of each line, regardless of varying line lengthsAenters insert mode at the end of each selected line- Type your text and press
<Esc>— the text appears at the end of every selected line
The key detail is $. Without it, <C-v> selects a fixed-width rectangle, which doesn't work well with lines of different lengths. Using $ tells Vim to extend to the end of each individual line.
Example
Given the text:
alpha
beta
gamma
Press <C-v>jj$A;<Esc> to append a semicolon to each line:
alpha;
beta;
gamma;
Tips
- Use
Iinstead ofAin block mode to prepend text at the block's left edge - The appended text only appears on all lines after you press
<Esc>— don't panic when you only see it on one line while typing - You can also use
:'<,'>norm A;as an alternative to achieve the same result - Combine with
ggandGto select all lines:ggV Gthen:'<,'>norm A; - Works great for adding trailing commas, semicolons, closing brackets, or comments to multiple lines