来源:http://www.cnblogs.com/lihaozy/archive/2012/08/06/2624909.html

(为了提高工作效率,必须学会使用一些工具)

. 查看 key 相关信息说明的命令 :help keycodes

==============================================================================================================
2. ctags
(1). 帮助手册查看
:help usr_29

(2). 功能
ctags的功能, 只要在unix/linux环境编程过的人都知道它的历害! 我在这也作个小小介绍吧: 对浏览代码非常的方便, 可以在函数, 变量之间跳来跳去等等.(注意: 我这里说到的仅是小小的一部分!).

(3). 安装
首先, 下载ctags安装包, 然后解压并安装, 命令如下:
$ tar -xzvf ctags-5.6.tar.gz
$ cd ctags-5.6
$ make
# make install   // 需要root权限 
        或:
        $ tar -xzvf ctags-5.7.tar.gz
        $ cd ctags-5.7
        $ ./configure
        # make
        # make install

(4). 使用方法
然后去你的源码目录, 如果你的源码是多层的目录, 就去最上层的目录, 在该目录下运行命令: ctags -R
我现在以 vim71 的源码目录做演示
$ cd /home/nuoerll/vim71
$ ctags -R

此时在/home/nuoerll/vim71目录下会生成一个 tags 文件, 现在用vim打开 /home/nuoerll/vim71/src/main.c
$ vim /home/nuoerll/vim71/src/main.c

再在vim中运行命令:
:set tags=/home/nuoerll/vim71/tags
该命令将tags文件加入到vim中来, 你也可以将这句话放到~/.vimrc中去, 如果你经常在这个工程编程的话.
对于经常在不同工程间编程, 可以在.vimrc中设置:
set tags=tags;    // ; 不能没有
set autochdir

(5). 使用例子
把光标定位到某一函数名上, 按下 Ctar + ], vim就可以自动切换到该函数定义处! 要返回只需要按下Ctrl + t .
更多用法, 在vim命令模式输入 :help usr_29 查看即可.

==============================================================================================================
3. TagList 插件
(1). 帮助手册查看
:help taglist.txt

(2). 功能
高效地浏览源码, 其功能就像vc中的workpace, 那里面列出了当前文件中的所有宏, 全局变量, 函数名等.

(3). 安装
下载taglist压缩包, 然后把解压的两个文件taglist.vim 和 taglist.txt 分别放到 $HOME/.vim/plugin 和 $HOME/.vim/doc 目录中.

(4). 使用方法
首先请先在你的~/.vimrc文件中添加下面语句:
let Tlist_Ctags_Cmd='/bin/ctags'   // 若在windows中应写成: let Tlist_Ctags_Cmd='ctags.exe'
let Tlist_Show_One_File=1
let Tlist_OnlyWindow=1
let Tlist_Use_Right_Window=0
let Tlist_Sort_Type='name'
let Tlist_Exit_OnlyWindow=1
let Tlist_Show_Menu=1
let Tlist_Max_Submenu_Items=10
let Tlist_Max_Tag_length=20
let Tlist_Use_SingleClick=0
let Tlist_Auto_Open=0
let Tlist_Close_On_Select=0
let Tlist_File_Fold_Auto_Close=1
let Tlist_GainFocus_On_ToggleOpen=0
let Tlist_Process_File_Always=1
let Tlist_WinHeight=10
let Tlist_WinWidth=18
let Tlist_Use_Horiz_Window=0

此时用vim打开一个c源文件试试:
$ vim ~/vim/src/main.c

进入vim后用下面的命令打开taglist窗口.
:Tlist

为了更方便地使用, 可以在.vimrc文件中加入:
map <silent> <leader>tl :TlistToggle<CR> 
这样就可以用 ",tl" 命令进行taglist窗口的打开和关闭之间方便切换了. // 这里的","是我.vimrc设置的leader, 你也可以设置成别的, 在.vimrc中修改即可, 如我的: let mapleader=","

==============================================================================================================
4. WinManager 插件
(1). 帮助手册查看
:help winmanager

(2). 功能
管理各个窗口, 或者说整合各个窗口.

(3). 安装
下载WinManager.zip压缩包, 解压后把*.vim文件放到 $HOME/.vim/plugin 目录中, 把*.txt文件放到 $HOME/.vim/doc 目录中.

(4). 使用方法
在.vimrc中加入如下设置:
let g:winManagerWindowLayout='FileExplorer|BufExplorer' // 这里可以设置为多个窗口, 如'FileExplorer|BufExplorer|TagList'
let g:persistentBehaviour=0      // 只剩一个窗口时, 退出vim.
let g:winManagerWidth=20
let g:defaultExplorer=1
nmap <silent> <leader>fir :FirstExplorerWindow<cr>
nmap <silent> <leader>bot :BottomExplorerWindow<cr>
nmap <silent> <leader>wm :WMToggle<cr>

(5). 使用例子
在终端输入vim启动vim:
$vim
在正常模式下, 敲入 ",wm" 即可看到, vim的左侧新建了两个窗口:FileExplorer和BufExplorer, 这样我们即可在FileExplorer窗口很方便地对目录进行查看, 编辑等操作; 在BufExplorer窗口中查看当前vim已经打开那些文件.

==============================================================================================================
5. cscope
(1). 帮助手册查看
:help if_cscop.txt

(2). 功能
用Cscope自己的话说 - "你可以把它当做是超过频的ctags", 其功能和强大程度可见一斑吧, 关于它的介绍我就不详细说了, 如果你安装好了前文介绍的帮助手册.

(3). 安装
    如果是在linux环境中, cscope一般都会随系统一起安装了; 在windows环境中, 则需要下载windows版本的(cscope.exe), 然后把它放到path环境变量所设
    置的目录中(如: C:\Program Files\Vim\vim72).

(4). 使用方法
    在.vimrc中增加如下设置, 就可以利用相应的快捷键进行不同的查找了.
        if has("cscope")
            set cscopetag   " 使支持用 Ctrl+] 和 Ctrl+t 快捷键在代码间跳来跳去
            " check cscope for definition of a symbol before checking ctags: set to 1
            " if you want the reverse search order.
            set csto=1

" add any cscope database in current directory
            if filereadable("cscope.out")
                cs add cscope.out 
            " else add the database pointed to by environment variable 
            elseif $CSCOPE_DB != ""
                cs add $CSCOPE_DB
            endif

" show msg when any other cscope db added
            set cscopeverbose

nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
            nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
            nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
            nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
            nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
            nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
            nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
            nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
        endif

(5). 使用例子
    首先进入源码目录, 在linux终端中输入以下命令以创建cscope数据库:
        $ find ~/work/..Project/ -name "*.h" -o -name "*.cpp" > cscope.files
        $ cscope -bkq -i cscope.files
    如果是在windows环境中, 则换成如下命令:
        dir /s /b *.cpp *.h > cscope.files
        cscope -b -q -k -i cscope.files

然后, 用vim打开一个源文件(如: vim main.cpp),
    打开后, 第一件事就是导入cscope数据库了:
        :cs add /home/yourname/workpace/cscope.out /home/yourname/workpace

cscope数据库导入成功后, 就可以利用"步骤(4)"中定义的快捷键进行相关的查找, 浏览等操作了(当然也可以直接利用相关命令, 嘿嘿).
                
==============================================================================================================
5. c.vim 插件
(1). 帮助手册查看
help csupport

(2). 功能
C/C++-IDE for Vim/gVim. 简单的说, 就是如果安装配置好后, vim/gvim就是一个c/c++编程的一个IDE, 其功能堪比windows里常用的vc.

(3). 安装
下载cvim.zip压缩包后, 把压缩包copy到 $HOME/.vim 目录(windows下, copy 到 C:\Program Files\Vim\vimfiles)下解压, 即可.
unzip cvim.zip    // 解压命令

(4). 使用方法
安装好后就可以直接用了, 具体例子看"使用例子".

(5). 使用例子
在终端用vim打开一个c文件:
$vim hello.c
进入vim, 敲入 "\im" 即可发现一个main函数框架就这样快捷简单完美地写出.

我比效常用的的操作有(第一列为命令, 第二列为说明, 第三列为该命令所支持的模式(n:普通模式, v:可视模式, i:插入模式):
    -- Help ---------------------------------------------------------------
    \hm       show manual for word under the cursor (n,i)
    \hp       show plugin help                      (n,i)

-- Comments -----------------------------------------------------------
    \cl       end-of-line comment                 (n,v,i)
    \cj       adjust end-of-line comment(s)       (n,v,i)
    \cs       set end-of-line comment column      (n)
    \c*       code -> comment /* */               (n,v)
    \cc       code -> comment //                  (n,v)
    \co       comment -> code                     (n,v)
    \cfr      frame comment                       (n,i)
    \cfu      function comment                    (n,i)
    \cme      method description                  (n,i)
    \ccl      class description                   (n,i)
    \cd       date                                (n,v,i)
    \ct       date \& time                        (n,v,i)

-- Statements ---------------------------------------------------------
    \sd       do { } while                        (n,v,i)
    \sfo      for { }                             (n,v,i)
    \sife     if { } else { }                     (n,v,i)
    \se       else { }                            (n,v,i)
    \swh      while { }                           (n,v,i)
    \ss       switch                              (n,v,i)

-- Preprocessor -------------------------------------------------------
    \p<       #include <>                         (n,i)
    \p"       #include ""                         (n,i)
    \pd       #define                             (n,i)
    \pu       #undef                              (n,i)
    \pie      #if #else #endif                   (n,v,i)
    \pid      #ifdef #else #endif                 (n,v,i)
    \pin      #ifndef #else #endif                (n,v,i)
    \pind     #ifndef #def #endif                 (n,v,i)
    \pi0      #if 0 #endif                        (n,v,i)
    \pr0      remove #if 0 #endif                 (n,i)
    \pe       #error                              (n,i)
    \pl       #line                               (n,i)
    \pp       #pragma                             (n,i)

-- Idioms -------------------------------------------------------------
    \if       function                            (n,v,i)
    \isf      static function                     (n,v,i)
    \im       main()                              (n,v,i)
    \i0       for( x=0; x<n; x+=1 )               (n,v,i)
    \in       for( x=n-1; x>=0; x-=1 )            (n,v,i)
    \ie       enum   + typedef                    (n,i)
    \is       struct + typedef                    (n,i)
    \iu       union + typedef                    (n,i)
    \ip       printf()                            (n,i)
    \isc      scanf()                             (n,i)
    \ica      p=calloc()                          (n,i)
    \ima      p=malloc()                          (n,i)
    \isi      sizeof()                            (n,v,i)
    \ias      assert()                            (n,v)
    \ii       open input file                     (n,i)
    \io       open output file                    (n,i)

-- Snippets -----------------------------------------------------------
    \nr       read code snippet                   (n,i)
    \nw       write code snippet                  (n,v,i)
    \ne       edit code snippet                   (n,i)
    \np       pick up prototype                   (n,v,i)
    \ni       insert prototype(s)                 (n,i)
    \nc       clear prototype(s)                 (n,i)
    \ns       show   prototype(s)                 (n,i)
    \ntl      edit local templates                (n,i)
    \ntg      edit global templates               (n,i)
    \ntr      rebuild templates                   (n,i)

-- C++ ----------------------------------------------------------------
    \+co      cout << << endl;                  (n,i)
    \+c       class                               (n,i)
    \+cn      class (using new)                   (n,i)
    \+ci      class implementation                (n,i)
    \+cni     class (using new) implementation    (n,i)
    \+mi      method implementation               (n,i)
    \+ai      accessor implementation             (n,i)

\+tc      template class                      (n,i)
    \+tcn     template class (using new)          (n,i)
    \+tci     template class implementation       (n,i)
    \+tcni    template class (using new) impl.    (n,i)
    \+tmi     template method implementation      (n,i)
    \+tai     template accessor implementation    (n,i)

\+tf      template function                   (n,i)
    \+ec      error class                         (n,i)
    \+tr      try ... catch                       (n,v,i)
    \+ca      catch                               (n,v,i)
    \+c.      catch(...)                          (n,v,i)

-- Run ----------------------------------------------------------------
    \rc       save and compile                    (n,i)
    \rl       link                                (n,i)
    \rr       run                                 (n,i)
    \ra       set comand line arguments           (n,i)
    \rm       run make                            (n,i)
    \rg       cmd. line arg. for make             (n,i)
    \rp       run splint                          (n,i)
    \ri       cmd. line arg. for splint           (n,i)
    \rk       run CodeCheck (TM)                  (n,i)
    \re       cmd. line arg. for CodeCheck (TM)   (n,i)
    \rd       run indent                          (n,v,i)
    \rh       hardcopy buffer                     (n,v,i)
    \rs       show plugin settings                (n,i)
    \rx       set xterm size                      (n, only Linux/UNIX & GUI)
    \ro       change output destination           (n,i)
    
关于此插件的更多功能和各种说明, 请查看帮助手册, help csupport.

==============================================================================================================
6. omnicppcoplete 插件
(1). 帮助手册查看
:help omnicppcoplete
(2). 功能
实现像vc那样的代码自动补全功能, 比如 this-><Ctrl+X><Ctrl+O> 后, 将出现一个提示框, 其中包含了this指针所有可以接收的函数或数据成员等.
(3). 安装
把下载下来的 omnicppcoplete-0.41.zip 压缩包copy到 $HOME/.vim/ (windows 复制到 C:\Program Files\Vim\vimfiles ), 然后解压, 即可.
(4). 使用方法
在.vimrc中添加以下两条语句:
        set nocp   "不兼容vi
        filetype plugin on   "开启文件类型识别功能
进入c++源码目录, 在终端执行命令 ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . 
(5). 使用例子
编写c++代码时, 如要自动补全, 敲入 Ctrl+X Ctrl+O, 即可在出现的提示框中用 Ctrl+N 选择符合要求的.

==============================================================================================================
7. a.vim插件
(1). 帮助手册查看
这个插件没有帮助手册, 不过大可放心使用, 其提供的功能也不是很多, 就几条命令, 但是用起来真的是很方便.
(2). 功能
在 .h 和 .c/.cpp 文件中切换. (英文原句 "A few of quick commands to swtich between source files and header files quickly.")
(3). 安装
把下载到的a.vim插件放到 $HOME/.vim/plugin 目录下, 即可.
(4). 使用方法
只要在vim中输入以下命令即可完成相应的功能:
:A switches to the header file corresponding to the current file being edited (or vise versa) 
:AS splits and switches 
:AV vertical splits and switches 
:AT new tab and switches 
:AN cycles through matches 
:IH switches to file under cursor 
:IHS splits and switches 
:IHV vertical splits and switches 
:IHT new tab and switches 
:IHN cycles through matches 
<Leader>ih switches to file under cursor 
<Leader>is switches to the alternate file of file under cursor (e.g. on <foo.h> switches to foo.cpp) 
<Leader>ihn cycles through matches

==============================================================================================================
8. VisualMark.vim插件
(1). 帮助手册查看
这个插件没有帮助手册, 不过大可放心使用, 其提供的功能也不是很多, 就几条命令, 但是用起来真的是很方便.
(2). 功能
高亮书签.
(3). 安装
把下载好的VisualMark.vim插件放到 $HOME/.vim/plugin 目录下, 即可.
(4). 使用方法
只要在vim中执行以下命令即可完成相应的功能:
   1. For gvim, use "Ctrl + F2" to toggle a visual mark. 
       For both vim and gvim, use "mm" to toggle a visual mark. 
   2. Use "F2" to navigate through the visual marks forward in the file. 
   3. Use "Shift + F2" to navigate backwards.

==============================================================================================================
9. Mark.vim插件
(1). 帮助手册查看
这个插件没有帮助手册, 不过大可放心使用, 其提供的功能也不是很多, 就几条命令, 但是用起来真的是很方便.

(2). 功能
这个插件与vim中自带的'*'与'#'非常相像. 不同之处是: vim中的'*'与'#'命令只能同时高亮一个同类词组(或正则表达式的搜索结果), 而Mark.vim插件可以同时高亮多个.

(3). 安装
把下载好的Mark.vim插件放到 $HOME/.vim/plugin 目录中, 即可.

(4). 使用方法
\m   mark or unmark the word under (or before) the cursor 
\r   manually input a regular expression. 用于搜索. 
\n   clear this mark (i.e. the mark under the cursor), or clear all highlighted marks .
\*   把光标向前切换到当前被Mark的MarkWords中的下一个MarkWord.
\#   把光标向后切换到当前被Mark的MarkWords中的上一个MarkWord.
\/ 把光标向前切换到所有被Mark的MarkWords中的下一个MarkWord.
\? 把光标向后切换到所有被Mark的MarkWords中的上一个MarkWord.

说明: 这些命令中的 '\' 是 vim 中的 mapleader, 你也可以设置为别的: 如, 若要设置为 ',', 把下面这条语句加到.vimrc文件中, 即可, 
   let mapleader=","

Vi经典插件ctags(转)相关推荐

  1. vim ctags java源码_如何使用vim的插件Ctags查看Linux源码

    一.ubuntu下安装Linux内核源码 (1).查看自己的内核版本 (2).查看源内的内核源码类表 (3).下载源码 (4).进入/usr/src (5).解压下载的文件到用户主 二.安装vim插件 ...

  2. 玩转vim之vim插件Ctags

    2012-11-09玩转vim之vim插件Ctags Ctags插件 插件介绍 Ctags工具是用来遍历源代码文件生成tags文件,这些tags文件能被编辑器或其它工具用来 快速查找定位源代码中的符号 ...

  3. iPhone5越狱后经典插件个人推荐

        最近过年在家,正好出了iphone5 iOS6的完美越狱,闲的无事,便折腾起越狱后的插件,一下是我测试的完美无bug插件名称,都是经典又实用的,特地给网友们分享一下. 1.AppSync fo ...

  4. sublime text3 的PHP函数追踪定位插件ctags和codeBeautifier

    一.下载ctags http://download.csdn.net/detail/xujunabc999/9604934 二.安装ctags和codeBeautifier插件: 1)按Ctrl+sh ...

  5. vi 经典配色 molokai.vim 配色安装

    1.安装后的效果图,如下: 2.将配色文件molokai.vim放在 ~/.vim/colors中,源文件下载地址:https://github.com/tomasr/molokai/blob/mas ...

  6. JQuery的45个经典插件应用

    jQuery滑动门 1) Slider Gallery- 这是一个模仿Apple网站的jQuery滑动门产品展示. 这个'产品展示滑动门'就是一个直线前进的画廊,在有限的空间里面显示产品图片,支持Ta ...

  7. Sublime Text3怎样在Deepin中配置CTags插件

    首先是要安装好Package Control,然后装插件CTags,这个时候在文件中右键已经能够出现Navigate to Definition菜单项了.然而,如果没有装CTags这个软件还是没用,所 ...

  8. 近100套经典VI欣赏下载

    1--杏花村VI手册经典下载(超棒) http://gaoerchina.com/bbs/showbb ... id=68&totable=1 2--中国银行VI http://gaoerch ...

  9. ubuntu ctags php,Ubuntu下创建vim+Taglist+cscope+ctags组合编辑器

    有人抱怨Linux系统下没有类似于VC之类的方便快捷的编辑器,有人用gedit, 有人用vim,但是都不方便而且也没有自动补全之类的方便用户的功能.本文简单介绍使用vim中的几个插件(Ctags.Cs ...

最新文章

  1. flexpaper 背景色变化
  2. 内存泄露调试工具visualleakdetector使用方法
  3. 小心,疫情下在线教育免费试听引起的“后遗症”
  4. 基于Java的全文索引
  5. Architecture:话说科学家/工程师/设计师/商人
  6. 可视化 nlp_使用nlp可视化尤利西斯
  7. vantUI 自定义引入iconfont图标(3种风格)- 案例篇
  8. C语言中的类模拟(C++编程思想)
  9. httpclient java 异步_Java的异步HttpClient
  10. IOCP实现聊天服务
  11. C语言基础5-预编译部分知识(#include+.h文件和.c文件的区别
  12. iPhone的MobileTerminal使用经验
  13. 智慧工地解决方案施工升降机智能监控系统
  14. 用Python 计算t分布的置信区间
  15. 安装Scipy出错的解决方法
  16. 0xc000007b的解决办法(续)
  17. SQL中is not null和!=“ “的区别
  18. 基于OpenCV的人脸识别考勤系统(三)
  19. 事务码ABAVN-资产卡片报废-BAPI_ASSET_RETIREMENT_POST
  20. HTTP 重定向状态码是什么意思?

热门文章

  1. java equals比较_Java中equals()和==的比较
  2. springBoot中启用事务管理
  3. [微信开发] 微信网页授权Java实现(https://www.cnblogs.com/lovebread/p/5513241.html)
  4. Azkaban安装部署,配置文件配置,启动等
  5. HIVE的安装配置、mysql的安装、hive创建表、创建分区、修改表等内容、hive beeline使用、HIVE的四种数据导入方式、使用Java代码执行hive的sql命令
  6. Zookeeper的安装部署,zookeeper参数配置说明,集群搭建,查看集群状态
  7. 6进程原语:wait()和waitpid()函数
  8. TopLink JPA
  9. Kettle使用_16 闭包Closure Generator树形数据
  10. aspmysql发布_ASP.NET Entity Framework with MySql服务器发布环境配置