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
to change it to
Now press cs'<q>
to change it to
To go full circle, press cst"
to get
To remove the delimiters entirely, press ds"
.
Now with the cursor on "Hello", press ysiw]
(iw
is a text object).
Let's make that braces and add some space (use }
instead of {
for no space): cs]{
Now wrap the entire line in parentheses with yssb
or yss)
.
Revert to the original text: ds{ds)
Emphasize hello: ysiw<em>
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.
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
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.
See the contribution guidelines for pathogen.vim.
Like surround.vim? Star the repository on GitHub and vote for it on vim.org.
Love surround.vim? Follow tpope on GitHub and Twitter.
Copyright (c) Tim Pope. Distributed under the same terms as Vim itself. See :help license
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4