Skip to content

Update README to clarify some points for Vim beginners. #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 53 additions & 20 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,48 +1,78 @@
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.
Surround.vim is a Vim plugin that 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
How to Use
----------

"Hello world!"

to change it to
Surround.vim may be easiest to explain by taking a look at a few examples.

'Hello world!'
### Single character surroundings

Now press `cs'<q>` to change it to

<q>Hello world!</q>

To go full circle, press `cst"` to get
Lets change a set of double quotes to single quotes. Surround.vim makes this
simple with four key strokes. Start with this bit of text:

"Hello world!"

To remove the delimiters entirely, press `ds"`.
Move your cursor so that it is within the double quotes. Now type the letter
`c` (change), the letter `s` (surround), the double quote `"`, and then the
single qoute `'`. The double quotes instantly become single quotes.

'Hello world!'

To remove the delimiters entirely, type `d` (delete), `s` (surround), and the
single quote `'`, all together like this: `ds'`.

Hello world!

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

Now with the cursor on the word "Hello", you surround it with brackets
by typing: `ysiw]`. (`iw` or "inner word" is one of Vim's
[text objects](http://vimdoc.sourceforge.net/htmldoc/motion.html#object-select),
you might think, "_you surround inner word_".)

[Hello] world!

This works with other text objects like sentences `is` and paragraphs `ip`.

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

For pairs of surrounds, use the beginning character `[` to surround
with some space. Use the ending `]` to surround tightly without space.

Let's change the brackets to braces and add some space. Type: `cs]{`.

{ Hello } world!

Now wrap the entire line in parentheses with `yssb` or `yss)`.
Now wrap the entire line in parentheses without space. Type: `yss)`.

({ Hello } world!)

Revert to the original text: `ds{ds)`
Revert to the original text with quotes: `ds)` `ds{` `yss"`

"Hello world!"

### Tag surroundings

HTML and XML tag surroundings are triggered with the `<` character, after
which you can type the whole tag and attributes.

Let's change the quotes to the html `<q>` tag. Type `cs"<q>`, and the
text instantly becomes:

<q>Hello world!</q>

When dealing with existing HTML or XML tags, you don't have to type
out the whole tag, just use `t` to refer to the immediately surrounding tag
pair. So, to _delete surrounding tags_ type: `dst`

Hello world!

Emphasize hello: `ysiw<em>`
_You surround_ an _inner word_ with the emphasis tag like this: `ysiw<em>`

<em>Hello</em> world!

Expand All @@ -52,6 +82,9 @@ visual mode) followed by `S<p class="important">`.
<p class="important">
<em>Hello</em> world!
</p>

Notes
-----

This plugin is very powerful for HTML and XML editing, a niche which
currently seems underfilled in Vim land. (As opposed to HTML/XML
Expand Down