VI经典插件ctags
Vi经典插件ctags(转)
(为了提高工作效率,必须学会使用一些工具)
. 查看 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的更多相关文章
- vim插件ctags的安装和使用
vim插件ctags的安装和使用 2013-11-19 20:47 17064人阅读 评论(0) 收藏 举报 分类: 开发工具(3) linux编程(9) c/c++编程(11) 版权声明:本 ...
- 拍案惊奇!9款神奇的jQuery/CSS3经典插件
款非常给力的jQuery/CSS3经典插件,插件包括CSS3图片特效.jQuery动画菜单.jQuery时尚登录表单等,一起来看看这些jQuery插件. .CSS3图片重力感应特效 这是一款应用重力感 ...
- sublime 函数跳转插件 — ctags 安装和使用
ctags 是 sublime 下一个函数跳转的插件,可以让你方便地从函数调用的位置跳到函数定义的位置.相对于其他插件,ctags 的安装稍微有点复杂,这里记录下备忘. 首先,假设已经安装 Packa ...
- VIM辅导:视频教程,文档资料,经典插件
VIM辅导:25个vim视频' 教程 '资源 转自: http://blog.jobbole.com/10250/ 编注:@程序员的那些事 12月14日在新浪微博发起的<你最常用哪些文本编辑 ...
- vim 插件 -- ctags
vim ctags 插件实现代码跳转的功能.希望在一个项目中快速的找到函数,变量,宏等定义的地方. 下载 http://ctags.sourceforge.net/ 安装 tar -jxvf ctag ...
- sublime text2 插件 - ctags的使用
第1步:安装Ctag.exe文件 1.下载ctags程序,下载地址:http://pan.baidu.com/share/link?shareid=2930217876&uk=20133352 ...
- sublime text3 插件CTags
1.打开Sublime Text 2/3软件,在Preferences(设置)菜单中打开Package Control(插件管理器)打开菜单后找到install packages,搜索ctags, 回 ...
- 使用VIM插件ctags来阅读C代码
说明 Ctags是vim下方便代码阅读的工具.尽管ctags也可以支持其它编辑器,但是它正式支持的只有vim.并且vim中已经默认安装ctags,它可以帮助程序员很容易地浏览源代码:ctags最先是用 ...
- vim插件ctags的安装与使用
LINUX系统下看程序或者编程序时,看到一个函数经常需要知道该函数的定义,这时ctags就派上用场了,其安装和使用方法如下: 安装方法: sudo apt-get install ctags (ubu ...
随机推荐
- Thread的六种状态
线程共有6种状态:在某一时刻只能是这6种状态之一.这些状态由Thread.State这个枚举类型表示,并且可以通过getState()方法获得当前具体的状态类型. 包括(new,runnable,bl ...
- hao dongxi
asp.net页面间传值方式后台 asp.net页面间传值的几种方法 利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. json的使用 前后台统一以对象的方式编程 ASP. ...
- 谢启鸿谈"如何学好高等代数"
高等代数和数学分析.空间解析几何一起,并称为数学系本科生的三大基础课.所谓基础课,顾名思义,就是本科四年学习的所有数学课程,都是以上述三门课作为基础的.因此对一年级新生而言,学好这三门基础课,其重要性 ...
- MySQL(七) —— MySQL存储过程 & 存储引擎
MySQL中输入语句的执行过程: 如果我们可以将上面的过程简化,吧语法分析或者编译等步骤简化,则可以将整个流程简化. 存储过程: 是SQL语句和控制语句的预编译集合,以一个名称存储并作为一个单元处理: ...
- How to evaluate a transimpedance amplifier (part 1)
In this blog, I want take a different approach and describe the technical challenge encountered whil ...
- 如何在PADS的封装中做非金属化孔
在设置封装的pads stacks的页面里,diameter,drill,plated三个项目(盘外径60mil,孔30mil) diameter:60,drill:30,plated:checked ...
- Socket通信常用方法
使用tcp协议,链接服务器的方法 /// <summary> /// 连接使用tcp协议的服务端 /// </summary> /// <param name=" ...
- JAVA运算符和优先级
1.算术运算符: ++ 和 -- 既可以出现在操作数的左边,也可以出现在右边,但结果是不同,如: ①int a=5: int b=a++: #先把a赋给b,a再自增 ②int a=5: int b=+ ...
- python_way day21 Django文件上传Form方式提交,原生Ajax提交字符处啊,Django文件上传之原生Ajax方式、jQuery Ajax方式、iframe方式,Django验证码,抽屉示例,
python_way day21 1.Django文件上传至Form方式 2.原生Ajax文件上传提交表单 使用原生Ajax好处:不依赖jquery,在发送一个很小的文件或者字符串的时候就可以用原生A ...
- CSharp Similarities and Differences
This document lists some basic differences between Nemerle and C# in a terse form. If you know Java ...