vimtricks.wiki Concise Vim tricks, one at a time.

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

  • d triggers the delete operator
  • it selects 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 cit to delete the content inside the tag and enter insert mode, ready to type a replacement
  • Use vit to 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

Next

How do I edit multiple lines at once using multiple cursors in Vim?