vim-surround
surround.vim: Delete/change/add parentheses/quotes/XML-tags/much more with ease
A Vim plugin that adds keyboard shortcuts for adding, changing, or removing surrounding characters like quotes, parentheses, and HTML tags in just a few keystrokes.
vim-surround is a plugin for the Vim text editor that makes it faster to work with paired characters like quotes, parentheses, brackets, and HTML or XML tags. These paired characters are called surroundings, and the plugin gives you keyboard shortcuts to add, change, or remove them without manually placing your cursor at both ends.
For example, if you have a word wrapped in double quotes and want to switch to single quotes, one short key sequence handles it. If you want to wrap a word in an HTML tag like a bold or emphasis tag, another sequence does that. Removing the surrounding characters entirely is a single command. The plugin also works in visual mode, so you can select a line or a block of text and wrap it in a tag or bracket all at once.
Most of the examples in the README involve switching between quote styles, adding brackets with or without spaces inside, and wrapping content in HTML tags. The plugin is described as particularly well-suited for editing HTML and XML, since changing both opening and closing tags simultaneously is otherwise tedious in a plain editor.
Installation uses Vim's built-in package system, or any third-party Vim plugin manager. There is also an optional companion plugin called repeat.vim that lets you redo surround operations with Vim's dot-repeat command, which normally does not work with custom plugin mappings.
The plugin is written by Tim Pope and is licensed under the same terms as Vim itself. It is one of several widely used Vim plugins from the same author.
Where it fits
- Switch a word from double quotes to single quotes in one key sequence without moving the cursor to both ends.
- Wrap a selected block of code or text in an HTML tag while editing a template file.
- Remove all surrounding parentheses from a function argument with a single command.
- Add brackets or custom delimiters around any word to format code or markup faster.