Overwrite insert in Vim

I want to be able to insert something from the buffer (possibly using "p"), but instead of pasting it into the text, I want to replace everything that was before. (Just like the "R" command), I searched Google, the vim and Stack Overflow documentation, but couldn't find anything on this. I guess this is just a team that I don't know about. Any help would be appreciated.

This is all I need to know, but if you want to know my specific problem:

Essentially, I'm just trying to create a short script for the documentation headers. At the beginning of each function, I add the following:

// FunctionName <> <> <> <<<>>>>> <<<> <> <> <> <> <> <> <> <>

However, adding all of these "<>" is annoying. I want so that I can put my cursor on the function name, press the F6 key and will produce the above. The problem, of course, is that function names are not constant sizes, and this will make the chain weird. So I just want to insert a BIG bunch of pre-made chains so that all this is always a constant number of characters. i.e:.

start with

//<><><><><><><><><><><><><><><><><><><><><><><><><><><> 

Insert "FunctionName" and terminate with

 // FunctionName <><><><><><><><><><><><><><><><><><><><> 

Thanks everyone

~ massager

+5
source share
2 answers

You can do this with this:

 :exe "normal ".strlen(@p)."x\"pP" 

It deletes the correct number of characters and then inserts the contents of register p .

+2
source

I found a much better solution

R Enter a replacement mode: each character you enter replaces an existing character, starting with the character under the cursor.

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

OLD ANSWER

You can do this with a macro quite 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 

Then the macro can be repeated using @h . You probably want to save this .vimrc this way

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

Note that the character ^[ must be a single character entered by pressing <ctrl-V><esc>

+7
source

Source: https://habr.com/ru/post/1200782/


All Articles