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

How do I repeat my last change on every line in a visual selection?

Answer

:'<,'>norm .

Explanation

The :'<,'>norm . command applies your last normal-mode change to every line in a visual selection. It combines the visual range ('<,'>), the :norm ex command (which runs a normal-mode sequence on each line), and the dot operator (.), which repeats the most recent change. This is ideal when you've already made one edit and want to replicate it across several lines without recording a macro.

How it works

  • '<,'> — the Ex range covering the visually selected lines
  • norm — execute the following keystrokes in normal mode, once per line
  • . — the dot operator, which replays the last change (including the count and motion used)

Example

You want to comment out several lines by prepending // . First, make the change on one line:

foo()
bar()
baz()

Press I// <Esc> on the first line:

// foo()
bar()
baz()

Now select bar() and baz() with Vj, then type :'<,'>norm .:

// foo()
// bar()
// baz()

Tips

  • This works with any change, not just insertions — deletions, substitutions, or anything the dot operator can replay
  • The change is replayed from the first column of each line; make sure your original edit starts from a predictable position
  • If the change depends on cursor position (e.g., a motion to the end of line), it will behave consistently on each line
  • For complex multi-step changes, a recorded macro (qq then :'<,'>norm @q) gives more control

Next

How do I override Vim's case sensitivity for a single search without changing the global ignorecase setting?