Aid in surrounding marked elements with whatever.
Go to file
Konfekt f4bd45d7de Turn \ into a prepended escape character like <space>
Turn \ into an additional escape character which precedes the surrround
character that follows \.

For example ysiw\B with the cursor at word gives \{word\}. That is, \ is
analogous to <space>.

This is useful in LaTeX where some surround characters such as {} must
be escaped to be displayed, and \( \) and \[ \] are used to display
math.
2016-02-20 20:10:11 +01:00
doc Keep HTML attributes when changing tags 2015-02-22 11:50:33 -05:00
plugin Turn \ into a prepended escape character like <space> 2016-02-20 20:10:11 +01:00
.gitignore Ignore doc/tags 2011-08-29 01:21:49 -04:00
README.markdown Clarify copyright 2011-08-30 20:32:41 -04:00

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

If you don't have a preferred installation method, I recommend installing pathogen.vim, and then simply copy and paste:

cd ~/.vim/bundle
git clone git://github.com/tpope/vim-surround.git

Once help tags have been generated, you can view the manual with :help surround.

Contributing

See the contribution guidelines for pathogen.vim.

Self-Promotion

Like surround.vim? Follow the repository on GitHub and vote for it on vim.org. And if you're feeling especially charitable, follow tpope on Twitter and GitHub.

License

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