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
  • 项目地址
  • 安装
  • 使用(翻译自官方文档)

Was this helpful?

  1. Vim 实操教程(Learning Vim)
  2. plugins

surround.vim

成对 添加、替换、删除 引号、括号 以及XML 标签

项目地址

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

安装

添加 .vimrc 配置

Plug 'tpope/vim-surround'

使用(翻译自官方文档)

先从最简单的例子开始。 在下面字符串内进行如下操作 cs"' (注意要在 NORMAL 模式下进行)

"Hello world!"

字符串将变成

'Hello world!'

再继续操作 cs'<q> 使其变成

<q>Hello world!</q>

将成对标签替换为 " 进行如下操作 cst",字符串将变成

"Hello world!"

ds" 将删除成对的 "

Hello world!

现在把光标移动到 "Hello" 这个单词内, 键入 ysiw] (iw 是文本对象)

[Hello] world!

接下来替换成大括号,并加上空格(使用 } 而不是 { 可以去掉空格): cs]{

{ Hello } world!

现在把整行放入小括号内,使用 yssb 或 yss)

({ Hello } world!)

恢复到原始的字符串: ds{ds)

Hello world!

将 Hello 嵌入斜体标签内: ysiw<em>

<em>Hello</em> world!

最后,我们来试试 VISUAL 模式。 键入大写的 V (行 VILUAL 模式) 接下来是 S<p class="important">

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

Last updated 1 year ago

Was this helpful?