在没有pathogen的状况下,vim插件的文件所有都放在.vim目录,卸载插件很麻烦,pathogen能够将不一样的插件放在一个单独的目录下,安装插件只须要将插件的文件夹复制到制定文件夹(bundle)内,卸载插件时只须要删除文件夹,方便好用。python
如下插件均可以采用“下载zip包到vundle文件夹,解压zip包”的方法进行安装c++
下载及安装https://github.com/tpope/vim-pathogengit
下载https://github.com/scrooloose/nerdtreegithub
下载https://github.com/godlygeek/tabularvim
下载https://github.com/majutsushi/tagbarui
下载https://github.com/bling/vim-airlinethis
下载https://github.com/tomasr/molokaispa
下载https://github.com/vim-scripts/mru.vimprototype
下载https://github.com/easymotion/vim-easymotion插件
下载https://github.com/kien/ctrlp.vim
下载https://github.com/vim-scripts/AutoComplPop
下载https://github.com/vim-scripts/OmniCppComplete
按键映射的配置都写在.vimrc中,.vimrc放在主目录
imap jk <ESC\> " 按jk退出编辑状态,不再用小指头按Esc了 map wq <ESC>:wq<CR> " 按wq就直接保存退出 imap wq <ESC>:wq<CR> " 按wq就直接保存退出 map qq <ESC>:q!<CR> " 按qq就直接不保存退出 imap qq <ESC>:q!<CR> " 按qq就直接不保存退出 map <F2> <ESC><C-W><C-W> " 按F2进行窗口切换,不按<C-W><C-W> map <F3> <ESC>:Tagbar<CR> " 按F3打开代码结构 map <F4> <ESC>:NERDTreeToggle<CR> map <F12> <ESC>:!ctags -R --c++-kinds=+px --fields=+aiKSz --extra=+q .<CR> " 按F12生成tag
map ,pp <ESC>:CtrlP<CR> "搜索文件 map ,pd <ESC>:CtrlPDir<CR> "搜索文件夹 map ,pu <ESC>:CtrlPUndo<CR> "搜索修改记录,能够回退 map ,pl <ESC>:CtrlPLine<CR> "搜索行 map ,pc <ESC>:CtrlPChangeAll<CR> "搜索修改记录,能够定位光标 map ,pm <ESC>:CtrlPMRU<CR> "搜索最近修改的文件
vim中的自动补全很麻烦,可是写代码没有自动补全彻底没法接受。为了实现自动补全,我一开始使用omnicppcomplete和AutoComplPop,后来据说有个牛逼的插件叫作YouCompleteMe,能够进行语法分析,实现自动补全,因而我就去试试。咱们的开发机没法访问外网,也不能直接用root用户下直接安装软件,安装YouCompleteMe确实麻烦。我前后用源码编译安装了cmake、llvm、python、vim和YouCompleteMe,花了很多时间,终于把YouCompleteMe装好了,不过使用的时候,补全仍是不够智能,没有想象中那么好。后来搬到了新的开发机,不想再从新安装YouCompleteMe了,从新回到omnicppcomplete和AutoComplPop。最后我发现,omnicppcomplete和AutoComplPop实现的补全效果比YouCompleteMe好。几乎每一个vim使用者都会面临自动补全的功能,在这里,我建议使用omnicppcomplete和AutoComplPop组合,简单方便,效果又好。
由于项目是使用blade build编译,BUILD记录了项目的依赖,因而我写了一个python脚本去分析BUILD文件,获取相应的依赖,再根据依赖去生成tag,提升代码补全能力。最终,vim的代码补全能力也不错!使用方法以下:
" set coding set termencoding=utf-8 set encoding=utf-8 set fileencoding=utf-8 set fenc=utf-8 set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936 set backspace=indent,eol,start set nocompatible " be iMproved, required set mouse=a " mouse useful set nu " set number set nocp set nobackup " no backup set noerrorbells " no voice set showmatch " show match of () {} [] set ignorecase " ignore case in search set cursorline " hightlight current line set cursorcolumn " hightlight current collum "set autochdir " auto change dir set autoindent " autoindent 是自动缩进, cindent是特别针对C语言语法自动缩进 set smartindent set cindent set tabstop=4 " 制表符为4 set softtabstop=4 set shiftwidth=4 set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离 set cmdheight=2 " 命令行(在状态行下)的高度,默认为1,这里是2 set statusline=%F%m%r%h%w[%p%%] " 个人状态行显示的内容 set laststatus=2 " 老是显示状态行 syntax on " 语法高亮 " key map imap jk <ESC> " 按jk退出编辑状态 map wq <ESC>:wq<CR> imap wq <ESC>:wq<CR> map qq <ESC>:q!<CR> imap qq <ESC>:q!<CR> map cp <ESC>:set mouse=c<CR>:set nonu<CR> map ncp <ESC>:set mouse=a<CR>:set nu<CR> map ,pa <ESC>:set paste<CR> map ,np <ESC>:set nopaste<CR> map gn <ESC>:tabnext<CR> map gm <ESC><C-W><C-W> map <F2> <ESC><C-W><C-W> map <F3> <ESC>:Tagbar<CR> map <F4> <ESC>:NERDTreeToggle<CR> map <F12> <ESC>:!ctags -R --c++-kinds=+px --fields=+aiKSz --extra=+q .<CR> "pathogen filetype off " required call pathogen#infect() filetype plugin on "theme syntax enable set t_Co=256 let g:airline_theme="dark" set background=dark colorscheme molokai "let g:AutoOpenWinManager = 1 let g:NERDTreeDirArrows = 1 let g:nerdtree_tabs_autoclose = 0 let g:bufExplorerSplitVertSize = 30 let g:bufExplorerMaxHeight=30 let g:winManagerWindowLayout = "FileExplorer|BufExplorer" let g:winManagerWidth = 30 "easymotion map / <Plug>(easymotion-sn) omap / <Plug>(easymotion-tn) map n <Plug>(easymotion-next) map N <Plug>(easymotion-prev) map <Leader>l <Plug>(easymotion-lineforward) map <Leader>j <Plug>(easymotion-j) map <Leader>k <Plug>(easymotion-k) map <Leader>h <Plug>(easymotion-linebackward) let g:EasyMotion_use_upper = 1 " Use uppercase target labels and type as a lower case let g:EasyMotion_smartcase = 1 " type `l` and match `l`&`L` let g:EasyMotion_use_smartsign_us = 1 " Smartsign (type `3` and match `3`&`#`) "easygrep let g:EasyGrepMode = 2 " All:0, Open Buffers:1, TrackExt:2 "let g:EasyGrepCommand = 0 " Use vimgrep:0, grepprg:1 let g:EasyGrepRecursive = 1 " Recursive searching let g:EasyGrepIgnoreCase = 1 " not ignorecase:0 let g:EasyGrepFilesToExclude = "*.bak, *~, cscope.*, *.a, *.o, *.pyc, *.bak" "let g:EasyGrepOpenWindowOnMatch = 0 "ctrlp let g:ctrlp_by_filename = 1 let g:ctrlp_working_path_mode = '0' "let g:ctrlp_cmd = 'CtrlPMixed' let g:ctrlp_match_window = 'bottom,order:ttb,min:1,max:10,results:20' "let g:ctrlp_regexp = 0 let g:ctrlp_extensions = ['buffertag', 'dir', 'undo', 'line', 'changes', 'mixed', 'bookmarkdir'] map ,pp <ESC>:CtrlP<CR> map ,pd <ESC>:CtrlPDir<CR> map ,pu <ESC>:CtrlPUndo<CR> map ,pl <ESC>:CtrlPLine<CR> map ,pc <ESC>:CtrlPChangeAll<CR> map ,pb <ESC>:CtrlPBookmarkDir<CR> map ,pm <ESC>:CtrlPMRU<CR> "acp let g:acp_enableAtStartup = 1 let g:acp_completeoptPreview = 0 let g:acp_ignorecaseOption = 1 let g:acp_behaviorKeywordCommand = "\<C-p>" let g:acp_behaviorKeywordLength = 1 "omnicppcomplete 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 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"] " au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif " 自动关闭补全窗口 set completeopt=menu,longest set tags+=./deps_tags