Pasting with overwrite in Vim

You can use visual selection.

  • Vp select the whole line and overwrite with buffer
  • viwp select the word under cursor and overwrite with buffer content.
  • vi(p overwrite what is in between parenthesis.

I particularly like that it highlights what should be overwritten, which makes it easier to verify.


I found a much better solution

R Enter Replace mode: Each character you type replaces an existing character, starting with the character under the cursor.

So R <ctrl-r>" will do what you want. Note there is a space before and after <ctrl-r>".

OLD ANSWER

You can do this with a macro pretty easily

qhmhA <esc>a<><esc>40.80|D`hq

qh start macro
mh set mark
A <esc> insert a space after the existing text
a<><esc> insert '<>'
40. repeat last command 40 times
80| move to column 80
D delete to the end of the line
`h jump back to mark
q end macro

The macro can then be repeated with @h. You probably want to save this to your .vimrc like so

let @h = 'mhA ^[a<>^[40.80|D`h'

Note that the ^[ are supposed to be one character entered by pressing <ctrl-V><esc>

Tags:

Vim