vim-addons插件的使用

来源:互联网 发布:林书豪15 16赛季数据 编辑:程序博客网 时间:2024/05/26 09:56

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插件了。

系统中已有的vim-scripts中包含的插件及其状态:

lingd@ubuntu:~$ vim-addons status

Name User Status System 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:~/.vimmkdirpluginlingd@ubuntu: /.vim mkdir doc

vim官方插件的安装,xxxx是要安装的插件名,以status中显示的名称为准。安装插件xxxx时使用以下命令(前提是在目录/home/user/.vim/下建立好了plugin和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 : 为标签增加类修饰符。注意,如果没有此选项,将不能对类成员补全

vim自动补全功能的测试

为了测试自动补全功能,我们先下载C++一份C++标准库的源代码。

lingd@ubuntu:~$ sudo apt-get install build-essential

然后在/usr/include/c++下就可以找到标准库的头文件了。

lingd@ubuntu:~cd/usr/include/c++lingd@ubuntu:/usr/include/c++ ls
4.4 4.4.3

在此文件夹下生成能与OmniCppComplete配合运作的tags文件

lingd@ubuntu:/usr/include/c++ctagsRc++kinds=+pfields=+iaSextra=+q.lingd@ubuntu:/usr/include/c++ ls
4.4 4.4.3 tags

在vim的配置文件中如下内容,然后在编程的时候就可以使用自动补全功能了。

lingd@ubuntu:/usr/include/c++$ vi ~/.vimrc

set tags+=/usr/include/c++/tags

用vi打开前面的Test.c文件,在printf(“Hello World!\n”)下一行中,输入pri,然后按下Ctrl+X Ctrl+O,此时vi会弹出一个窗口,所有以pri开头的tag都会出现在这个窗口中,printf就出现在第6行中

lingd@ubuntu:~cd lingd@ubuntu:  vim Test.c

0 0
原创粉丝点击