Delete the inner content of an HTML tag
After yesterday's TIL, fellow Hashrocketeer Jack Rosa shared with me a few other cool ways to delete things in vim.
My favorite way that he showed me that I never knew existed was using dit
.
This deletes all content of the HTML tag you are inside of.
Let's use the following HTML for a couple examples:
1 |<div>
2 | <h1>Header</h1>
3 |
4 | <p>
5 | This is some paragraph text that is <em>emphasized</em> for importance.
6 | </p>
7 |</div>
If your cursor was anywhere within the <div></div>
without being inside of a nested element, the result would be:
1 |<div></div>
If your cursor was anywhere within <em>emphasized</em>
, the result would be:
1 |<div>
2 | <h1>Header</h1>
3 |
4 | <p>
5 | This is some paragraph text that is <em></em> for importance.
6 | </p>
7 |</div>
Conclusion: This is a nice and easy way to clear out html tags quickly.
Tweet