Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1691620
  • 博文数量: 410
  • 博客积分: 9563
  • 博客等级: 中将
  • 技术积分: 4517
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-03 19:59
个人简介

文章分类

全部博文(410)

文章存档

2017年(6)

2016年(1)

2015年(3)

2014年(4)

2013年(32)

2012年(45)

2011年(179)

2010年(140)

分类: LINUX

2011-06-02 23:04:04

  写程序时,尤其在C/C++程序中,有大量的配对的符号(surrounding):( ), [ ], { }, < > ‘ ‘, ” “,另外标记语言(如XML)更是由无数的配对标记组成:,

. 如果能够快速地处理这些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插件帮助文档中的示例:

  1. Old text                   Command                    New text ~
  2. "Hello *world!"             ds"                       Hello world!
  3. [123+4*56]/2                cs])                      (123+456)/2
  4. "Look ma, I'm *HTML!"       cs"               Look ma, I'm HTML!
  5. if *x>3 {                   ysW(                       if ( x>3 ) {
  6. my $str = *whee!;           vlllls'                  my $str = 'whee!';
  7. Yo!*
            dst                            Yo!
  • Yo!*
  •             cst

                     

    Yo!


    其中,*表示光标所在位置。
      下面是surround.vim插件支持的快捷键的列表:

    Normal mode -----------
    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。

    阅读(1319) | 评论(0) | 转发(0) |
    给主人留下些什么吧!~~