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

How do I append the same text to the end of several lines?

Answer

V select then :norm A text

Explanation

Selecting lines and running :norm A text appends the same text to the end of every selected line. This is often simpler than visual block mode.

How it works

  1. Select lines with V and motions
  2. Type : (auto-fills '<,'>)
  3. Type norm A; (or whatever text to append)
  4. Press Enter

Example

let x = 1
let y = 2
let z = 3

Select all three lines, run :'<,'>norm A;:

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

Tips

  • norm I// prepends // to each line
  • norm! uses built-in key meanings (ignores custom mappings)
  • More flexible than block mode for lines of different lengths
  • :%norm A; applies to every line in the file
  • Works with any normal mode command, not just A/I

Next

How do you yank a single word into a named register?