vim-surround README

The project's README from github.com/tpope/vim-surround. As one markdown file: README.md.

surround.vim

Surround.vim is all about "surroundings": parentheses, brackets, quotes, XML tags, and more. The plugin provides mappings to easily delete, change and add such surroundings in pairs.

It's easiest to explain with examples. Press cs"' inside

"Hello world!"

to change it to

'Hello world!'

Now press cs'<q> to change it to

<q>Hello world!</q>

To go full circle, press cst" to get

"Hello world!"

To remove the delimiters entirely, press ds".

Hello world!

Now with the cursor on "Hello", press ysiw] (iw is a text object).

[Hello] world!

Let's make that braces and add some space (use } instead of { for no space): cs]{

{ Hello } world!

Now wrap the entire line in parentheses with yssb or yss).

({ Hello } world!)

Revert to the original text: ds{ds)

Hello world!

Emphasize hello: ysiw<em>

<em>Hello</em> world!

Finally, let's try out visual mode. Press a capital V (for linewise visual mode) followed by S<p class="important">.

<p class="important">
  <em>Hello</em> world!
</p>

This plugin is very powerful for HTML and XML editing, a niche which currently seems underfilled in Vim land. (As opposed to HTML/XML inserting, for which many plugins are available). Adding, changing, and removing pairs of tags simultaneously is a breeze.

The . command will work with ds, cs, and yss if you install repeat.vim.

Installation

Install using your favorite package manager, or use Vim's built-in package support:

mkdir -p ~/.vim/pack/tpope/start
cd ~/.vim/pack/tpope/start
git clone https://tpope.io/vim/surround.git
vim -u NONE -c "helptags surround/doc" -c q

FAQ

How do I surround without adding a space?

Only the opening brackets—[, {, and (—add a space. Use a closing bracket, or the b (() and B ({) aliases.

Contributing

See the contribution guidelines for pathogen.vim.

Self-Promotion

Like surround.vim? Star the repository on GitHub and vote for it on vim.org.

Love surround.vim? Follow tpope on GitHub and Twitter.

License

Copyright (c) Tim Pope. Distributed under the same terms as Vim itself. See :help license.

vim-surround (tpope/vim-surround)

Searching Database…

What is this?A Vim plugin that adds mappings to delete, change, and add surrounding pairs like parentheses, brackets, quotes, and XML/HTML tags.
Is this a standalone app or a Vim plugin?It's a Vim plugin (editor script), not a standalone application; it only works inside Vim.
Do I need any other plugin for it to work?No dependencies are required to use the core mappings, but installing repeat.vim lets the dot command (.) repeat ds, cs, and yss actions.
How do I surround text without adding extra space?Using an opening bracket like (, {, or [ adds a space inside; use the closing bracket (or the b/B aliases) instead to avoid the space.
What are the basic commands to learn?ds deletes a surrounding pair, cs changes one pair to another, and ys/yss adds surroundings around a motion or a whole line; in visual mode, S wraps the selection.
Is this good for editing HTML or XML tags?Yes, the README calls it very powerful for HTML/XML editing since it can add, change, and remove matching tag pairs at once, a niche it says is underfilled in Vim.
Creator
tpope
Size
0.1 MB
Stars
14.1K
Updated
CommitOct 25
Age
18y
Commits · 90 Days