How to Wrap HTML Element(s) With Another HTML Element in Vim

How to Wrap HTML Element(s) With Another HTML Element in Vim

Using the very popular vim-surround plugin, we can accomplish this task easily.

Here, we have five anchor tags.

<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Gallery</a>
<a href="#">Contact</a
<a href="#">Others</a

In order to wrap all of them between a nav element, we have to first select all five anchor elements by using linewise visual mode and then type S<nav>.

<nav>
  <a href="#">Home</a>
  <a href="#">About</a>
  <a href="#">Gallery</a>
  <a href="#">Contact</a
  <a href="#">Others</a
</nav>