vimtricks.wiki Concise Vim tricks, one at a time.

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

  1. Select lines in visual mode (or specify a range)
  2. Type :normal A; and press Enter
  3. 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
  • :normal is 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

Next

How do I always access my last yanked text regardless of deletes?