Contunuing my series of posts on awesome, indispensible Vim plugins, today let’s meet vim-surround! Vim-surround allows you to manipulate text/tags/quotes that surround a chuck of code.
Delete Surroundings with
<h3>Welcome to Snarnia!</h3>
command to run with cursor anywhere on the line (even in tag.)
Welcome to Snarnia!
Change Surroundings with
"Hello, Bossy" to
<q>Hello, Bossy</q> with:
Add Surrounding text with
Adding text makes use of vim’s yanking word movements. Suppose you want to add, quotes around a sentence:
I'm a monster, as well as a dwarf. You should charge me double. --Tyrion Lannister
Command, on same line as quotation:
"I'm a monster, as well as a dwarf." You should charge me double." --Tyrion Lannister
I have found vim-surround especially helpful when editing html.
Manipulate outer tags
One more tip for manipulating outer tags: add a numeric argument to work on outer tags.
<div> <ul> <li>one</li> <li>more</li> <li>thing</li> <ul> </div>
In order to delete the
<div> tag while in a list item in the code up above, type:
ds3t and that will delete the tag 3 layers up.
<ul> <li>one</li> <li>more</li> <li>thing</li> <ul>