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
- Press
<C-v>to enter block mode - Select lines with
j - Press
$to extend to end of each line - Press
Ato append - 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