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.
No, but you can select visually and put your text:
vitp
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With