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

How do I append a semicolon to every line in a file using :norm?

Answer

:%norm A;

Explanation

The :%norm command runs normal mode commands on every line in the file (or a range). This is incredibly powerful for batch edits — appending text, deleting characters, or running any normal mode sequence on multiple lines without macros.

How it works

  • :%norm {commands} — execute normal mode commands on every line
  • :'<,'>norm {commands} — execute on visually selected lines
  • :10,20norm {commands} — execute on lines 10-20
  • Commands run as if you typed them in normal mode on each line

Example

" Append semicolon to every line
:%norm A;

" Delete first 2 characters of each line
:%norm xx

" Add 'const ' before each line
:%norm Iconst 
Before :%norm A;:
let x = 1
let y = 2
let z = 3

After:
let x = 1;
let y = 2;
let z = 3;

Tips

  • Use norm! (with bang) to ignore user mappings — safer in scripts
  • :g/pattern/norm {cmd} runs normal commands only on matching lines
  • :%norm @a runs macro a on every line
  • For insert mode text, include the full sequence: :%norm I// adds comment prefix

Next

How do I return to normal mode from absolutely any mode in Vim?