Learn VIM
  • Vim Hands-On Tutorial (Learning Vi and Vims)
  • Vim Hands-On Tutorial(Learning Vim)
    • Chapter 1: Cursor Movement
    • Chapter 2: Opening Files, Finding Content
    • Chapter 3: Modifying and Saving Files
    • Chapter 4: Some Tips
    • Chapter 5: Splitting Windows and Tabs
    • Chapter 6: Block Operations
    • Chapter 7: Vim Macros
    • Vim Modes
    • Vim Plugins
    • plugins
      • Airline & Themes
      • EasyAlign
      • Plugin Recommendations
      • NERDTree
      • surround.vim
  • Vim 实操教程(Learning Vim)
    • 第一章:光标移动
    • 第二章:打开文件、查找内容
    • 第三章:文档的修改与保存
    • 第四章:一些小技巧
    • 第五章:分屏与标签页
    • 第六章:块操作
    • 第七章:Vim 中的宏
    • Vim 的模式
    • Vim 插件
    • plugins
      • Airline & Themes
      • EasyAlign
      • 插件推荐
      • NERDTree
      • surround.vim
Powered by GitBook
On this page
  • Project Address
  • Installation
  • Usage (from official documentation)

Was this helpful?

  1. Vim Hands-On Tutorial(Learning Vim)
  2. plugins

surround.vim

Add, replace, and delete quotes, brackets, and XML tags in pairs.

Project Address

https://github.com/tpope/vim-surround

Installation

Add the following configuration to your .vimrc file

Plug 'tpope/vim-surround'

Usage (from official documentation)

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.

PreviousNERDTreeNextVim 实操教程(Learning Vim)

Last updated 1 year ago

Was this helpful?

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

repeat.vim