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>
(c
hanges
urroundingt
ag 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.