vim代碼補全終極配置

來源:互聯網
上載者:User

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.csupport

2.2 下載外掛程式

下載外掛程式(紅色為本節配置使用到的外掛程式),並存放在~/.vim/plugin/下。

|-- c.vim|-- neocomplcache.vim|-- snippet.vim|-- supertab.vim|-- taglist.vim

2.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 = {}endiflet 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:charreturn "\<Right>"elsereturn 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程式。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.