How do I append text at the end of lines with different lengths using visual block?
Answer
<C-v>j$A;<Esc>
Explanation
When lines have varying lengths, a normal visual block selection stops at the shortest line. Using $ in visual block mode extends the selection to the end of every line regardless of length, allowing you to append text at the true end of each line.
How it works
<C-v>— enter visual block modej(repeated) — extend selection down$— extend selection to end of each line (ragged right edge)A— append after the selection on every line- Type your text, then
<Esc>— applies to all lines
Example
Before:
foo
foobar
foo baz quux
After (appending ';'):
foo;
foobar;
foo baz quux;
Tips
- Without
$, block selection is rectangular and won't reach the end of longer lines - This is ideal for adding semicolons, commas, or closing brackets to lines of varying length
- Use
Iinstead ofAto insert at the beginning of the block selection - Combine with
gvto reselect and apply another transformation