How do I delete the content inside an HTML tag?
Answer
dit
Explanation
The dit command deletes the text inside the nearest enclosing HTML or XML tag pair without removing the tags themselves. It combines the d (delete) operator with the it (inner tag) text object.
How it works
dtriggers the delete operatoritselects the inner tag text object — everything between the opening and closing tags, but not the tags themselves
Example
Given the text with the cursor anywhere inside the <p> tag:
<p>Hello, world!</p>
Pressing dit results in:
<p></p>
The content Hello, world! is deleted but the <p> and </p> tags remain intact.
Tips
- Use
dat("a tag") to delete the content and the surrounding tags - Use
citto delete the content inside the tag and enter insert mode, ready to type a replacement - Use
vitto visually select the content inside the tag first - Works with nested tags — Vim finds the nearest enclosing tag pair from the cursor position
- Also works with self-closing tags and multi-line tag content