您的位置:首页 > 编程语言

vim代码自动补全函数提示设置

2014-11-12 22:02 267 查看
分类: Linux2011-12-23
19:36 16590人阅读 评论(2) 收藏 举报

vimautocompletenamespacesvbaautoloadprototype

   vim中不能代码补全让人感觉很不爽,以下配置就是进行代码补全的,虽然功能没有windows下IDE功能强大,但是也足够用了。

   需要插件为:neocomplcache,OmniCppComplete,Autocomplpop,code_complete。另外,还需要ctags插件,但是这个插件一般vim内置,所以不用管。

neocomplcache:

地址:http://www.vim.org/scripts/script.php?script_id=2620,这个插件有zip和vba两种格式,首选vba。这种格式可以直接安装,不用手动分别安装各个文件。具体步骤如下:

1、下载vba格式插件;

2、使用命令:vim neocomplcache*.vba

3、在vim命令状态下:so %

                                     :q

插件会自动安装到相应文件夹。

之后,修改版.vimrc文件,加入以下:

syntax on

set tabstop=4

set softtabstop=4

set shiftwidth=4

set autoindent

set cindent

set nu

if &term=="xterm"

  set t_Co=8

  set t_Sb=^[[4%dm

  set t_Sf=^[[3%dm

endif

let g:neocomplcache_enable_at_startup = 1

Autocomplpop:

地址:http://www.vim.org/scripts/script.php?script_id=1879,下载后为zip格式,解压后把各文件放入相应文件夹(/usr/share/vim/**)。

该插件只能根据已有的代码,提供最简单的代码提示,不能根据C++中重要的操作符提供代码提示。该功能还得由OmniCppComplete插件提供。

OmniCppComplete:

地址:http://www.vim.org/scripts/script.php?script_id=1520

这个插件是基于ctags数据库即tags文件实现的。

当我们自己下载Vim插件的时候,也可以另外建立目录,放置我们自己的插件。这个目录一般为/home/user/.vim,另外还需要建立一个插件子目录,一个插件文档子目录,以上的可以进入/home/user目录下通过下面的命令执行:

mkdir .vim

cd .vim

mkdir plugin

mkdir doc

然后将下载到的zip文件放到.vim目录下,直接解压(插件也包括两个目录,一个plugin,一个doc,所以它会自动放置到对应的目录)。

注意,我在ubuntu10.10把omnicppcomplete-0.41.zip解压后有三个文件夹:after, autoload, doc我直接把这三个文件夹放在 .vim这个文件夹下,并没有放在plugin文件夹里面,因为我把这三个文件夹放在plugin文件夹下面打开vim也就是用vim编辑一个文件的时候会又出错信息,但是放在 .vim也可以正常自动补全,两种方法都试一下看看。

unzip omnicppcomplete-0.41.zip

插件这就算安装完了。然后再到vim配置文件中加入如下的配置:

"-- omnicppcomplete setting --

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

let OmniCpp_DisplayMode=1

let OmniCpp_DefaultNamespaces=["std"]

(前几行就是提供了C++中的./->/::等操作符的提示和自动完成)。

 确保已关闭了vi兼容模式,并允许进行文件类型检测:

   set nocp

   filetype plugin on

   生成标签文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: