How do I repeat an edit on multiple lines in Vim?

Ctrl-v enters visual mode blockwise. You can then move (hjkl-wise, as normal), and if you want to insert something on multiple lines, use Shift-i.

So for the text:

abc123abc
def456def
ghi789ghi

if you hit Ctrl-v with your cursor over the 1, hit j twice to go down two columns, then Shift-i,ESC , your text would look like this:

abc,123abc
def,456def
ghi,789ghi

(the multi-line insert has a little lag, and won't render until AFTER you hit ESC).


That's what the :norm(al) command is for:

:10,20 normal I,

:10,20s/^/,/

Or use a macro, record with:

q a i , ESC j h q

use with:

@ a

Explanation: q a starts recording a macro to register a, q ends recording. There are registers a to z available for this.

Tags:

Vim