分类: LINUX
2011-09-16 17:07:04
. 如果能够快速地处理这些surroundings,就能大大提升编程的效率。
Vim本身就有这种配对符号的能力,在Vim中这叫做text object,可以使用:h text-objects查看这些text
objects。你会发现Vim只能对这些配对符所包含的文本或者整个text
object进行删除和修改,却不能对surrounding进行修改,更不能为普通文本添加surrounding。
既然有这种需求,就肯定会有热心人士努力,来满足这种需求,方便了自己,也方便了整个Vim用户群。就为Vim写了这款插件,surround.vim:
This plugin is a tool for dealing with pairs of “surroundings.” Examples of surroundings include parentheses, quotes, and HTML tags. They are closely related to what Vim refers to as |text-objects|. Provided are mappings to allow for removing, changing, and adding surroundings.
下面是surround.vim插件帮助文档中的示例:
Old text Command New text ~Look ma, I'm HTML!
if *x>3 { ysW( if ( x>3 ) {
my $str = *whee!; vlllls' my $str = 'whee!';
Yo!*dst Yo!
Yo!*cst
Yo!
其中,*表示光标所在位置。
Normal mode
下面是surround.vim插件支持的快捷键的列表:
-----------
ds - delete a surrounding
cs - change a surrounding
ys - add a surrounding
yS - add a surrounding and place the surrounded text on a new line + indent it
yss - add a surrounding to the whole line
ySs - add a surrounding to the whole line, place it on a new line + indent it
ySS - same as ySs
Visual mode
-----------
s - in visual mode, add a surrounding
S - in visual mode, add a surrounding but place text on new line + indent it
Insert mode
------------ in insert mode, add a surrounding - in insert mode, add a new line + surrounding + indent s - same as S - same as
关于这些快捷键,更加详析的解释参见该插件的help文档。
需要注意的一点是,安装此插件后,在Visual Mode内原来的s与S(substitute)命令便不再有效,如果你经常在V模式下使用替换命令,你可能需要对该插件略作修改,将V模式下对应的键映射代码注释掉。
另外,如果你在终端中使用Vim,Insert Mode中使用Ctrl + s键时,则可能会使终端冻结(Ctrl + q解除冻结)。此时你可以使用对应的Ctrl + g版本的快捷键。
最后,你可以在,安装方式和其它插件相同:把得到的zip文件解压缩到.vim下即可,为了使用help文档,可能还需要执行一次:helptags ~/.vim/doc。====