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

vim代码补全终极配置

2011-04-15 13:05 344 查看

1. 先来看看效果图

2. 配置方法


<1>.效果图

下面的效果如如果没有特殊说明,均是不需要按代码提示的快捷键(例如ctrl+p等)的,看看效果,是不是很想visual assist。

1.1 结构struct和枚举enum代码提示:



1.2 用户定义函数代码提示



1.3 用户定义变量代码提示



1.4 c++ class method代码提示:



1.5 class属性代码提示



1.6 c library代码提示



<2>.配置方法

2.1 安装ctags并生成tag文件

安装ctags xuqiang@ubuntu:~/Documents/vim/test$ sudo apt-get install ctags

为linux下的c头文件生成tag文件,如果想要为其他的库生成tag文件,原理同下:

xuqiang@ubuntu:~/Documents/vim/test$ sudo ctags -f c --recurse --verbose其中-f制定tag文件的名字,--recurse表明递归生成当前目录下的所有文件和文件夹。--verbose表明在控制台中打印当前生成进度信息。最好将生成的tag文件保存到一个特定的目录中,这里我是存放在了.vim下:xuqiang@ubuntu:~/.vim$ lsafter c-support exUtility-4.2.0 plugin tagsautoload doc ftplugin README.csupport2.2 下载插件

下载插件(红色为本节配置使用到的插件),并存放在~/.vim/plugin/下。

|-- c.vim|-- neocomplcache.vim|-- snippet.vim|-- supertab.vim|-- taglist.vim2.3 .vimrc配置文件

" prérequis tags

set nocp filetype plugin on " configure tags - add additional tags here or comment out not-used ones " load user definition tags " set tags+=~/.vim/tags/stl set tags+=~/.vim/tags/c" linux header file tag" set tags+=~/.vim/tags/linuxkernel" set tags+=~/.vim/tags/sdl " set tags+=~/.vim/tags/qt4 " build tags of your own project with CTRL+F12 map <C-F11> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR> noremap <F11> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<cr> inoremap <F11> <Esc>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<cr> " OmniCppComplete " let OmniCpp_NamespaceSearch = 1 " let OmniCpp_GlobalScopeSearch = 1 " let OmniCpp_ShowAccess = 1 " let OmniCpp_MayCompleteDot = 1 " let OmniCpp_MayCompleteArrow = 1 " let OmniCpp_MayCompleteScope = 1 " let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"] " automatically open and close the popup menu / preview window au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif set completeopt=menuone,menu,longest,previewlet g:SuperTabRetainCompletionType = 2let g:SuperTabDefaultCompletionType = "<C-X><C-O>" let g:AutoComplPop_MappingDriven = 0let g:acp_enableAtStartup = 1let g:acp_ignorecaseOption = 1let g:acp_completeOption = '.,w,b,k'" """""""""""""""""""""""""""""configuration for neocomplcache""""""""""""""""""""""""""""" Disable AutoComplPop.let g:acp_enableAtStartup = 0" Use neocomplcache.let g:neocomplcache_enable_at_startup = 1 " Use smartcase.let g:neocomplcache_enable_smart_case = 1" Use camel case completion.let g:neocomplcache_enable_camel_case_completion = 1" Use underbar completion.let g:neocomplcache_enable_underbar_completion = 1" Set minimum syntax keyword length.let g:neocomplcache_min_syntax_length = 1" set the max list in the popup menu. increase the speedlet g:neocomplcache_max_list=20" Define keyword.if !exists('g:neocomplcache_keyword_patterns') let g:neocomplcache_keyword_patterns = {}endif let g:neocomplcache_keyword_patterns['default'] = '\h\w*'let g:neocomplcache_auto_completion_start_length=1" ignore letter caselet g:neocomplcache_enable_ignore_case=1" """""""""""""""""""""""""""""configuration for neocomplcache""""""""""""""""""""""""""""" """"""""""""""""""""""""""auto complete () "" """""""""""""""""""""""""""""""""""""""":inoremap ( ()<ESC>i:inoremap ) <c-r>=ClosePair(')')<CR>:inoremap { {}<ESC>i:inoremap } <c-r>=ClosePair('}')<CR>:inoremap [ []<ESC>i:inoremap ] <c-r>=ClosePair(']')<CR>:inoremap < <><ESC>i:inoremap > <c-r>=ClosePair('>')<CR>function ClosePair(char)if getline('.')[col('.') - 1] == a:char return "\<Right>"else return a:charendifendf" """"""""""""""""""""""""""auto complete () "" """"""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""line number"""""""""""""""""""""""""""""""""""""""""""""'set nu" """"""""""""""""""""""""""""line number"""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""auto indent """"""""""""""""""""""""""""""""""""""""set autoindentset cindent" """""""""""""""""""""""""""""auto indent """"""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""syntax on"""""""""""""""""""""""""""""""""""""""""""""syntax on" """""""""""""""""""""""""""""""syntax on """"""""""""""""""""""""""""""""""""""""""""需要注意的是,默认的情况下vim是不会加载 set tags+=~/.vim/tags/c文件的,需要使用命令:NeoComplCacheCachingTags

暂时仅仅能够完成的一个文件的代码提示,下面几篇中还将介绍如何使用vim来管理项目文件,如何使用vim来debug c程序。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: