Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There's cit, dit, yit (change, delete, yank inside tag) on vim... is there something like pit (paste inside tag?)

Tags:

vim

Using vim I'm used to motion command like cit, dit, yit when editing html/xml files. I like . even more after using this commands because I can repeat what I did with just one keystroke.

I would like to know if theres something like pit (paste inside tag) already available, that deletes inside the tag and paste what I wanted (from + register for example) and make . available like cit, or if I'll need to create a mapping for that.

like image 522
Somebody still uses you MS-DOS Avatar asked Jul 20 '11 21:07

Somebody still uses you MS-DOS


2 Answers

No, but you can select visually and put your text:

vitp
like image 60
sidyll Avatar answered Nov 13 '22 03:11

sidyll


The excellent vim-ReplaceWithRegister by Ingo Karat is most likely what you are looking for.

It defines the gr object to enable pasting the vim way for any motion:

USAGE
------------------------------------------------------------------------------

    [count]["x]gr{motion}   Replace {motion} text with the contents of register x.
                            Especially when using the unnamed register, this is
                            quicker than "_d{motion}P or "_c{motion}<C-R>"
    [count]["x]grr          Replace [count] lines with the contents of register x.
                            To replace from the cursor position to the end of the
                            line use ["x]gr$
    {Visual}["x]gr          Replace the selection with the contents of register x.

Example, say you have to following buffer with tags with cursor at the first line:

<mytag> aaa </mytag>
<mytag> bbb </mytag>
<mytag> ccc </mytag>

yit yanks aaa into the unnamed register "" as usual. But if you go down to the next line (j), you can now replace with grit (paste in tag) the vim way, without overwriting the "". Therefore, if you repeat grit on the 3rd line, you'll also replace ccc with aaa. Of course, just hitting . to repeat the last operation makes this even quicker.

It also plays nicely with the global command, i.e. after yanking, you could just :%g/mytag/norm grit to replace apply it on all line containing mytag.

like image 1
Sebastian Müller Avatar answered Nov 13 '22 02:11

Sebastian Müller