1、管理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插件了。
lingd@ubuntu:~$ vim-addons status
align 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-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
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 removed removed
vcscommand removed removed
vimplate removed removed
whatdomain removed removed
winmanager removed removed
xmledit removed removed
上面我们介绍了如何独立于系统配置文件之外,建立自己的Vim配置文件。当我们自己下载安装Vim插件的时候,也可以另外建立目录,放置我们自己的插件。这个目录一般为/home/user/.vim,另外还需要建立一个插件子目录,一个插件文档子目录,以上的可以进入/home/user目录下通过下面的命令执行:
lingd@ubuntu:~
mkdir.vimlingd@ubuntu:
cd .vim
lingd@ubuntu:~/.vim
mkdirpluginlingd@ubuntu: /.vim
mkdir doc
vim-addons install xxxx
关于vim-addons命令的详细用法,可以通过“man vim-addons”查看其帮助文档
2、vim自动补全——OmniCppComplete
vim的自动补全功能可通过其插件OmniCppComplete实现。
安装OmniCppComplete
lingd@ubuntu:~$ vim-addons install omnicppcomplete
配置OmniCppComplete
在vim配置文件/home/user/.vimrc中加入如下的配置:
“– omnicppcomplete setting –
” 按下F3自动补全代码,注意该映射语句后不能有其他字符,包括tab;否则按下F3会自动补全一些乱码
imap
” 按下F2根据头文件内关键字补全
imap
set completeopt=menu,menuone ” 关掉智能补全时的预览窗口
let OmniCpp_MayCompleteDot = 1 ” autocomplete with .
let OmniCpp_MayCompleteArrow = 1 ” autocomplete with ->
let OmniCpp_MayCompleteScope = 1 ” autocomplete with ::
let OmniCpp_SelectFirstItem = 2 ” select first item (but don’t insert)
let OmniCpp_NamespaceSearch = 2 ” search namespaces in this and included files
let OmniCpp_ShowPrototypeInAbbr = 1 ” show function prototype in popup window
let OmniCpp_GlobalScopeSearch=1 ” enable the global scope search
let OmniCpp_DisplayMode=1 ” Class scope completion mode: always show all members
“let OmniCpp_DefaultNamespaces=[“std”]
let OmniCpp_ShowScopeInAbbr=1 ” show scope in abbreviation and remove the last column
let OmniCpp_ShowAccess=1
(前几行就是提供了C++中的./->/::等操作符的提示和自动完成)。
OmniCppComplete是基于ctags数据库即tags文件实现的(基于ctags生成的索引信息来实现自动补全的),所以在ctags -R生成tags时还需要一些额外的选项,这样生成的tags文件才能与OmniCppComplete配合运作。使用下列命令生成tags文件,就可以与OmniCppComplete配合运作:
ctags -R –c++-kinds=+p –fields=+iaS –extra=+q .
–c++-kinds=+p : 为C++文件增加函数原型的标签
–fields=+iaS : 在标签文件中加入继承信息(i)、类成员的访问控制信息(a)、以及函数的指纹(S)
–extra=+q : 为标签增加类修饰符。注意,如果没有此选项,将不能对类成员补全
lingd@ubuntu:~$ sudo apt-get install build-essential
lingd@ubuntu:~
cd/usr/include/c++lingd@ubuntu:/usr/include/c++
ls
4.4 4.4.3
lingd@ubuntu:/usr/include/c++
ctags−R–c++−kinds=+p–fields=+iaS–extra=+q.lingd@ubuntu:/usr/include/c++
ls
4.4 4.4.3 tags
lingd@ubuntu:/usr/include/c++$ vi ~/.vimrc
set tags+=/usr/include/c++/tags
lingd@ubuntu:~ cd lingd@ubuntu: vim Test.c