How to change the pair of a changed HTML tag in Vim

htmlvim

How can I configure Vim so that when I change one member of a matching pair of HTML tags, the other is automatically changed to match?

For example: given <span>content</span>, I want to change <span> to <div>, and then the closing </span> automatically changes to </div>. Optimally this would happen upon returning from insert mode to normal mode, but it would be OK if I had to hit a special keybinding to make this happen.

Best Answer

The excellent surround.vim makes this simple — with the cursor anywhere within the tag you want to change, in normal mode, type cst<div> (change surrounding tag to <div>). The tag name will be changed to "div" in both the opening and closing tag, and you'll be back in normal mode.

Related Question