Basic Overview of the Surround Plugin for Vim
Surround is a useful Vim plugin when hand-editing HTML or XML. The plugin can be downloaded via Github or the Vim website and installed by copying the /plugin/surround.vim file to your ~/.vim/plugin/ directory. A few of its basic commands are as follows. Note that each command is entered from within the text to be surrounded:
Adding Surroundings
Generally, the cs or ys commands can be used to add surroundings.
Add Surrounding
1 2 | ysiw<tag> csw<tag> |
Add Surrounding to Highlighted Text From Within Visual Mode:
1 | VS<tag> |
Add Surrounding
1 | yss<tag> |
Add Surrounding to Line, Place it on a New Line, and Indent It:
1 2 | ySs<tag> ySS<tag> |
Changing Surroundings
Surroundings can be changed with the cs command.
Change Surrounding
1 | cst<newtag> |
Change Surrounding Puncuation, in this Case Changing a Double Quote to a Single Quote:
1 | cs"' |
Deleting Surroundings
Delete Innermost Surrounding
1 | dst |
Delete Surrounding Quotes (Also works with parentheses, brackets, etc.):
1 | ds" |
Delete Text Within a
While this isn't a function of Surround.vim, I find it somewhat relevant to the above operations. Luckily, it’s built into Vim.
1 | dit |