How do I append the same suffix to every selected line in Visual mode?
Answer
:'<,'>normal! A;
Explanation
Visual selections are not just for direct operators; they also define an Ex range. A powerful pattern is applying :normal over '<,'> so the same normal-mode edit runs on each selected line. This lets you perform repeatable, cursor-aware edits without recording a macro or entering block mode.
How it works
:'<,'>is the line range defined by the current Visual selectionnormal!executes raw normal-mode keys (ignores mappings)A;moves to end of each line and appends;
Because this runs line-by-line through the selected range, you get deterministic edits even when line lengths differ.
Example
Select these lines in Visual line mode:
let x = 1
let y = 2
let z = x + y
Run:
:'<,'>normal! A;
Result:
let x = 1;
let y = 2;
let z = x + y;
Tips
- Swap
A;for any normal edit, for exampleI//to prepend comments - Use
normal!(notnormal) when you need predictable behavior regardless of mappings - This approach composes well with prior narrowing via Visual selection