How do I add text to the end of every line in a range?
Answer
:'<,'>normal A;
Explanation
The :normal command executes normal-mode keystrokes on every line in a range. Combined with A (append to end of line), this is the fastest way to add text to multiple lines without recording a macro.
How it works
- Select lines in visual mode (or specify a range)
- Type
:normal A;and press Enter - Vim executes
A;on each line — appending a semicolon
Examples
" Add semicolons to lines 10-20
:10,20normal A;
" Add a comment to all selected lines
:'<,'>normal I//
" Delete first 4 characters of every line
:10,20normal 4x
" Wrap every line in quotes
:%normal I"^[A"
" (^[ is a literal Escape, entered with <C-v><Esc>)
" Indent every line
:%normal >>
Using :normal!
" normal! ignores user mappings (uses default Vim behavior)
:%normal! A;
The ! variant is safer in scripts and plugins because it bypasses custom key mappings.
Tips
- To enter special keys like
<Esc>in:normal, press<C-v>first to insert the literal key code :normalis essentially a single-line macro applied to a range- For more complex operations, combine with
:g::g/pattern/normal A; - This replaces visual block mode (
<C-v>) for many use cases and is often more reliable