1、将Vim改造为强大的IDEVim集成CtagsTaglistCscopeWinmanagerNERDTreeOmniCppComplete有图有真相1、安装Vim和Vim基本插件首先安装好Vim和Vim的基本插件。这些使用apt-get安装即可:lingdubuntu:/arm$sudo apt-get install vim vim-scripts vim-doc其中vim-scripts是vim的一些基本插件,包括语法高亮的支持、缩进等等。vim中文帮助文档tar包下载地址:解压后其中有个doc文件夹, 将其中的内容全部复制到/.vim/doc, 或者vim安装目录下的doc目录中, 此时
2、vim中的help信息已经是中文的了.网页版中文帮助文档网址首页就时vim帮助文档的目录,阅读起来更方便有效、更有针对性!2、Vim配置文件Vim强大的功能,其来源基本上就两个地方:Vim插件以及Vim配置文件。Vim本身的系统配置文件夹是在/usr/share/vim/和/etc/vim/两个文件夹下。一般情况下,我们不会去改变这两个文件夹下的配置文件,而是在用户文件夹/home/user(其中,user为用户名,我的用户名是lingd)下建立自己的配置文件。进入用户文件夹(/home/user/)之后,用gedit新建一个名叫.vimrc的文件:lingdubuntu:/arm$ cd l
3、ingdubuntu:$ gedit .vimrc注:使用gedit主要是为了方便大段大段的文字粘贴!然后把下面的文字拷贝进这个文件之后保存: This line should not be removed as it ensures that various options are properly set to work with the Vim-related packages available in Debian.debian.vim Uncomment the next line to make Vim more Vi-compatible NOTE: debian.vim set
4、s nocompatible. Setting compatible changes numerous options, so any other options should be set AFTER setting compatible.set nocompatible Vim5 and later versions support syntax highlighting. Uncommenting the following enables syntax highlighting by default.if has(syntax)syntax on 语法高亮endifcolorschem
5、e ron elflord ron peachpuff default 设置配色方案,vim自带的配色方案保存在/usr/share/vim/vim72/colors目录下 detect file typefiletype onfiletype plugin on If using a dark background within the editing area and syntax highlighting turn on this option as wellset background=dark Uncomment the following to have Vim jump to t
6、he last position when reopening a fileif has(autocmd)au BufReadPost * if line() 1 & line() 1s,=1s,:1s 设置C/C+语言的具体缩进方式set backspace=2 设置退格键可用set showmatch 设置匹配模式,显示匹配的括号set linebreak 整词换行set whichwrap=b,s, 光标从行首和行末时可以跳到另一行去set hidden Hide buffers when they are abandonedset mouse=a Enable mouse usage
7、(all modes) 使用鼠标set number Enable line number 显示行号set previewwindow 标识预览窗口set history=50 set command history to 50 历史记录50条-状态行设置-set laststatus=2 总显示最后一个窗口的状态行;设为1则窗口数多于一个的时候显示最后一个窗口的状态行;0不显示最后一个窗口的状态行set ruler 标尺,用于显示光标位置的行号和列号,逗号分隔。每个窗口都有自己的标尺。如果窗口有状态行,标尺在那里显示。否则,它显示在屏幕的最后一行上。-命令行设置-set showcmd 命令
8、行显示输入的命令set showmode 命令行显示vim当前模式-find setting-set incsearch 输入字符串就显示匹配点set hlsearch注:配置文件中,以单个双引号开头的文字为注释。保存文件之后,启动Vim。此时,Vim已经是这种效果了(语法高亮挺漂亮的这个是由vim-scripts中的插件支持的):3、ctags安装与配置ctags可以建立源码树的标签索引(标签就是一个标识符被定义的地方,如函数定义),使程序员在编程时能迅速定位函数、变量、宏定义等位置去查看原形以下是在ubuntu下ctags的下载安装和配置过程:下载并安装ctags,终端输入命令lingdu
9、buntu:/arm$ sudo apt-get install ctags建立源码索引,比如我经常需要查阅Linux的内核代码,而这些代码放在/home/lingd/arm/linux-2.6.24.7目录下那么在终端进入到该目录后,输入命令ctags -R *,你会发现多了一个tags文件,这个就是索引文件lingdubuntu:/arm$ cd linux-2.6.24.7lingdubuntu:/arm/linux-2.6.24.7$ lsarch crypto include kernel mm samples usrblock Documentation init lib net
10、scriptsCOPYING drivers ipc MAINTAINERS README securityCREDITS fs Kbuild Makefile REPORTING-BUGS soundlingdubuntu:/arm/linux-2.6.24.7$ ctags -R *lingdubuntu:/arm/linux-2.6.24.7$ lsarch crypto include kernel mm samples tagsblock Documentation init lib net scripts usrCOPYING drivers ipc MAINTAINERS REA
11、DME securityCREDITS fs Kbuild Makefile REPORTING-BUGS sound向vim注册索引文件tags的路径,lingdubuntu:/arm/linux-2.6.24.7$ vi /.vimrc在打开文件的最后添加如下内容(当然,具体路径根据你自己的情况)-ctags setting- 按下F5重新生成tag文件,并更新taglistmap :!ctags -R -c+-kinds=+p -fields=+iaS -extra=+q . :TlistUpdateimap :!ctags -R -c+-kinds=+p -fields=+iaS -e
12、xtra=+q . :TlistUpdateset tags=tagsset tags+=./tags add current directorys generated tags fileset tags+=/arm/linux-2.6.24.7/tags add new tags file(刚刚生成tags的路径,在ctags -R 生成tags文件后,不要将tags移动到别的目录,否则ctrl+时,会提示找不到源码文件)set tags+=./tags表示在当前工作目录下搜索tags文件set tags+=/arm/linux-2.6.24.7/tags表示在搜寻tags文件的时候,也要搜
13、寻/arm/linux-2.6.24.7/文件夹下的tags文件。然后保存并退出vi。这样,你就可以用vim在任意地方查看有关Linux的函数原形tag命令用法:Ctrl 跳到当前光标下单词的标签CtrlO 返回上一个标签CtrlT 返回上一个标签:tag TagName 跳到TagName标签以上命令是在当前窗口显示标签,当前窗口的文件替代为包标签的文件,当前窗口光标跳到标签位置。如果不希望在当前窗口显示标签,可以使用以下命令::stag TagName 新窗口显示TagName标签,光标跳到标签处CtrlW + 新窗口显示当前光标下单词的标签,光标跳到标签处当一个标签有多个匹配项时(函数
14、(或类中的方法) 被多次定义),:tags 命令会跳转到第一处。如果在当前文件中存在匹配,那它将会被首先使用。可以用这些命令在各匹配的标签间移动::tfirst 到第一个匹配:counttprevious 向前 count 个匹配:counttnext 向后 count 个匹配:tlast 到最后一个匹配或者使用以下命令选择要跳转到哪一个:tselect TagName输入以上命令后,vim会为你展示一个选择列表。然后你可以输入要跳转到的匹配代号 (在第一列)。其它列的信息可以让你知道标签在何处被定义过。以下命令将在预览窗口显示标签:ptag TagName 预览窗口显示TagName标签,光
15、标跳到标签处CtrlW + 预览窗口显示当前光标下单词的标签,光标跳到标签处:pclose 关闭预览窗口:pedit file.h 在预览窗口中编辑文件file.h(在编辑头文件时很有用):psearch atoi 查找当前文件和任何包含文件中的单词并在预览窗口中显示匹配,在使用没有标签文件的库函数时十分有用。最简单的使用方法举例用vi在任意目录写一个Test.c文件,内容如下:int main(void)printf(Hello World!n);return 0;写好后末行模式输入w保存好(不要退出vi),按Esc回到指令模式,把光标停留在printf上然后按 CtrlW + ,vi会自动
16、跳到Linux系统函数printf()处,这时我们能查看printf()的原形查看完了,按Ctrlo(回到上一个标签) 就回到原来的地方4、管理vim插件vim-addons通过vim-addons,我们可以管理vim插件。我们在sudo apt-get install vim vim-scripts vim-doc时,一般会自动安装上vim-addons。若未安装可通过sudo apt-get install vim-addon-manager手动安装。安装完成后,就可以用vim-addons管理vim插件了。# 系统中已有的vim-scripts中包含的插件及其状态:lingdubuntu
17、:$ vim-addons status# Name User Status System Statusalign removed removed alternate removed removed bufexplorer removed removed calendar removed removed closetag removed removed colors sampler pack removed removed cvsmenu removed removed debPlugin removed removed detectindent removed removed doxygen
18、-toolkit removed removed editexisting removed removed enhanced-commentify removed removed gnupg removed removed info removed removed justify removed removed lbdbq removed removed markdown-syntax removed removed matchit removed removed minibufexplorer installed removed nerd-commenter removed removed
19、omnicppcomplete installed removed po removed removed project installed removed python-indent removed removed secure-modelines removed removed snippetsEmu removed removed sokoban removed removed supertab removed removed surround removed removed taglist installed removed tetris removed removed utl rem
20、oved removed vcscommand removed removed vimplate removed removed whatdomain removed removed winmanager removed removed xmledit removed removed 上面我们介绍了如何独立于系统配置文件之外,建立自己的Vim配置文件。当我们自己下载安装Vim插件的时候,也可以另外建立目录,放置我们自己的插件。这个目录一般为/home/user/.vim,另外还需要建立一个插件子目录,一个插件文档子目录,以上的可以进入/home/user目录下通过下面的命令执行:lingdub
21、untu:$ mkdir .vimlingdubuntu:$ cd .vimlingdubuntu:/.vim$ mkdir pluginlingdubuntu:/.vim$ mkdir doc# vim官方插件的安装,xxxx是要安装的插件名,以status中显示的名称为准。安装插件xxxx时使用以下命令(前提是在目录/home/user/.vim/下建立好了plugin和doc两个文件夹)vim-addons install xxxx关于vim-addons命令的详细用法,可以通过“man vim-addons”查看其帮助文档5、vim自动补全OmniCppCompletevim的自动补全
22、功能可通过其插件OmniCppComplete实现。安装OmniCppCompletelingdubuntu:$ vim-addons install omnicppcomplete配置OmniCppComplete在vim配置文件/home/user/.vimrc中加入如下的配置:- omnicppcomplete setting - 按下F3自动补全代码,注意该映射语句后不能有其他字符,包括tab;否则按下F3会自动补全一些乱码imap 按下F2根据头文件内关键字补全imap set completeopt=menu,menuone 关掉智能补全时的预览窗口let OmniCpp_MayC
23、ompleteDot = 1 autocomplete with .let OmniCpp_MayCompleteArrow = 1 autocomplete with -let OmniCpp_MayCompleteScope = 1 autocomplete with :let OmniCpp_SelectFirstItem = 2 select first item (but dont insert)let OmniCpp_NamespaceSearch = 2 search namespaces in this and included fileslet OmniCpp_ShowPrototypeInAbbr = 1 show function prototype in popup windowlet OmniCpp_GlobalScopeSearch=1 enable the global scope searchlet OmniCpp_DisplayMode=1 Class scope completion mode:
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2