=======================================
安装vim相关软件
=======================================
2 安装 ctags 5.8 ctags.sourceforge.net
CentOS6 和 Debian7 安装系统自带的
3 安装 安装Cscope cscope.sourceforge.net
tar zxvf cscope-15.8a.tar.gz &&
cd cscope-15.8a &&
./configure --prefix=/usr/local &&
make &&
make install
{解决了cscope的不退出一键更新的问题
su -
cd /usr/local/include/boost/
find |grep -E ".(c|cc|cp|cpp|cxx|ipp|c++|h|h++|hh|hp|hpp|hxx)$" >cscope.files
cscope -bq -i cscope.files
exit
cd
vi .vimrc
加入:
cs add ~/Ice-3.4.2/cpp/cscope.out ~/Ice-3.4.2/cpp
cs add ~/Ice-3.4.2/ThirdParty/db-4.8.30.NC/cscope.out ~/Ice-3.4.2/ThirdParty/db-4.8.30.NC
cs add /usr/local/include/boost/cscope.out /usr/local/include/boost/
}
=======================================
安装VIM插件
=======================================
插件安装目录: ~/.vim/plugin/ 帮助文件目录: ~/.vim/doc/
拷贝新的帮助文件后,执行: vim -c "helptags ~/.vim/doc" -c "q"
1 安装 AutoTag 1.13版 自动更新tags的插件
{ This utility will only work when using vim that's been compiled with python support. }
把 autotag.vim 拷贝到: ~/.vim/plugin/ 目录下。
修改 autotag.vim
217行改为:
cmd = "%s -R --c++-kinds=+p --fields=+iaS --extra=+q -f %s -a " % (self.ctags_cmd, self.tags_file)
219行改为:
cmd = "%s -R --c++-kinds=+p --fields=+iaS --extra=+q -a " % (self.ctags_cmd,)
2 安装 TagList 4.6版
cd ~/.vim/doc
mv taglist.txt taglist2.txt
vi taglist2.txt
{ 修改: *taglist.txt* 为 *taglist2.txt* }
vim -c "helptags ~/.vim/doc" -c "q"
3 安装 showfunc.vim
这个插件实现了按下fd,就可以提示当前光标所在函数的定义,另外还实现了当输入'('时,会自动匹配tags,展示函数的定义原型
只需要把这个插件放到plugin下就行,不需要配置。
4 安装 OmniCppComplete 自动补全
安装
执行: vim -c "helptags ~/.vim/doc" -c "q"
{
1) 生成 C函数的tags
su -
mkdir /opt/bk
cd /usr/include
mv c++ /opt/bk/.
exit
ctags -R --c-kinds=+p --fields=+iaS --extra=+q --language-force=C -f ~/.vim/c_tags /usr/include
su -
mv /opt/bk/* /usr/include/.
exit
2) 生成 C++函数的tags
下载 cpp_src.tar.bz2
解压到: /usr/local
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ -f ~/.vim/cpp_tags /usr/local/cpp_src
3) 生成 ICE的tags
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ --append=yes -f ~/.vim/ice_tags ~/Ice-3.4.2/cpp/include
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ --append=yes -f ~/.vim/ice_tags ~/Ice-3.4.2/cpp/src
4) 生成 BDB的tags
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.vim/bdb_tags ~/Ice-3.4.2/ThirdParty/db-4.8.30.NC
5) 生成 其它的tags
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --append=yes -f ~/.vim/misc_tags ~/Ice-3.4.2/ThirdParty/bzip2-1.0.6
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --append=yes -f ~/.vim/misc_tags /usr/local/include/mongo
x) 修改以下tags文件中的路径 /home/yucheng 为: ~
sed -i "s//home/yucheng/~/g" ice_tags bdb_tags misc_tags
}
vi ~/.vimrc
{
set tags=~/.vim/ice_tags,~/.vim/bdb_tags,~/.vim/misc_tags,~/.vim/cpp_tags,~/.vim/c_tags,../../include/tags,../include/tags,./tags
}
5 安装 WinManager
先安装 bufexplorer.vim
然后安装 WinManager
执行: vim -c "helptags ~/.vim/doc" -c "q"
在 .vimrc 中加入以下几行:
let g:winManagerWindowLayout='FileExplorer|TagList' " 设置窗口布局
let g:winManagerWidth=40
nmap <f12> :WMToggle<cr>
imap <f12> <esc><f12>a
以后就可以随时使用f12键来快速开关我们的file窗口和taglist窗口了
6 安装 MiniBufExplorer
Copy minibufexpl.vim into your plugin directory
7 安装 visualmark 高亮书签
Copy visualmark.vim into your plugin directory
8 安装 grep.vim 在工程中查找
在 .vimrc 中增加配置
nmap <silent> <F3> :Grep<CR>
let Grep_Default_Filelist = '*.h *.hpp *.cpp *.cxx *.c'
{
把光标移动到需要查找的单词上,按F3
命令行显示要搜索的内容,可以修改,如:加上正则表达式。也可以不修改,直接回车
命令行显示要查找的文件,可以修改。回车
会弹出QuickFix窗口,列出所有符合条件的搜索结果
}
9 安装 NERD_commenter.vim 注释插件 2.3.0 版
执行: vim -c "helptags ~/.vim/doc" -c "q"
map <c-h> ,c<space> "这样的话,在光标所在行上,按下一次ctrl+h是注释,再按下一次是取消注释
其内建的指令,cm是多行注释,类似C++的/**/,,cu是取消注释
(安装后,无效,why? )
10 安装 DoxygenToolkit.vim 生成Doxygen风格的注释
Copy to your '~/.vim/plugin' directory
11 安装 a.vim 快速切换.cpp和.h文件
把a.vim放到plugin下,不需要配置
直接可以:A,打开.cpp和.h对应的文件,:AV,打开.cpp和.h对应的文件,并且分屏
=======================================
.vimrc 下文中出现"美元符" 是因显示问题
=======================================
if v:lang =~ "^zh_CN"
set fileencodings=gb18030
set guifontset=*-r-*
elseif v:lang =~ "utf8美元符" || v:lang =~ "UTF-8美元符"
set fileencodings=utf-8,latin1
elseif v:lang =~ "^zh_TW"
set fileencodings=big5
set guifontset=-sony-fixed-medium-r-normal--16-150-75-75-c-80-iso8859-1,-taipei-fixed-medium-r-normal--16-150-75-75-c-160-big5-0
elseif v:lang =~ "^ko"
set fileencodings=euc-kr
set guifontset=-*-*-medium-r-normal--16-*-*-*-*-*-*-*
elseif v:lang =~ "^ja_JP"
set fileencodings=euc-jp
set guifontset=-misc-fixed-medium-r-normal--14-*-*-*-*-*-*-*
endif
" 对语言的支持,utf8和gbk之类
set fileencodings=gb18030,gbk,gb2312,big5,utf-8,latin1,euc-jp,euc-kr,ucs-bom,cp936
if(has("win32") || has("win95") || has("win64") || has("win16")) "判定当前操作系统类型
let g:iswindows=1
else
let g:iswindows=0
endif
if &term=="xterm"
set t_Co=8
set t_Sb=^[4%dm
set t_Sf=^[3%dm
endif
" Only do this part when compiled with support for autocommands
if has("autocmd")
" In text files, always limit the width of text to 78 characters
autocmd BufRead *.txt set tw=78
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
syntax enable
" if &t_Co > 2 || has("gui_running")
syntax on
" set hlsearch
" endif
set mouse=a
set nocompatible " Use Vim defaults (much better!)
set bs=2 " allow backspacing over everything in insert mode
"set ai " always set autoindenting on
"set backup " keep a backup file
set viminfo='20,"50 " read/write a .viminfo file, don't store more than 50 lines of registers
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set number " 显示行号
set autoindent " 智能自动缩进
set smartindent " 开启新行时使用智能自动缩进
set shiftwidth=4 " 缩进所表示的空格数
set tabstop=4
set expandtab " 用空格替换tab字符
%retab
set softtabstop=4 " 使得按退格键时可以一次删掉 4 个空格
filetype plugin indent on " 让filetype-plugin根据文件类型自动缩进
set hlsearch " 对被搜索的表达式显示高亮
set incsearch " 在输入要搜索的文字时,实时匹配
set foldenable " 开始折叠 :help zo
set foldmethod=syntax " 设置语法折叠
set foldcolumn=0 " 设置折叠区域的宽度
set foldlevel=100 " 启动vim时不要自动折叠代码
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cscope的设置
" 查看帮助 :help if_cscop.txt
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("cscope")
set csprg=/usr/local/bin/cscope
" 优选搜索标签库,未找到匹配项后搜索cscope数据库
set csto=1
" vim内置命令 同时搜索cscope数据库和标签库
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif 美元符CSCOPE_DB != ""
cs add 美元符CSCOPE_DB
endif
" 添加cscope.out文件 Ice BDB mongodb
" cs add ~/source/Ice-3.5.0/cpp/cscope.out ~/source/Ice-3.5.0/cpp
" cs add ~/source/db-5.3.21.NC/cscope.out ~/source/db-5.3.21.NC
" cs add ~/source/mongodb-src-r2.4.1/cscope.out ~/source/mongodb-src-r2.4.1
" 给出添加cscope数据库成功与否信息
set csverb
" 用 quickfix 窗口来显示 cscope 结果
set cscopequickfix=s-,c-,d-,i-,t-,e-
" cscope用的快捷键
nmap <F9>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<CR>
imap <F9>s <esc><F9>s
nmap <F9>g :cs find g <C-R>=expand("<cword>")<CR><CR>
imap <F9>g <esc><F9>g
nmap <F9>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR>
imap <F9>d <esc><F9>d
nmap <F9>c :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR>
imap <F9>c <esc><F9>c
nmap <F9>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR>
imap <F9>t <esc><F9>t
nmap <F9>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR>
imap <F9>e <esc><F9>e
nmap <F9>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
imap <F9>f <esc><F9>f
nmap <F9>i :cs find i <C-R>=expand("<cfile>")<CR><CR>:copen<CR>
imap <F9>i <esc><F9>i
endif " if has("cscope")
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 快捷键设置
" nmap 是command模式, imap 是insert模式
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" F3 --- 查找
nmap <silent> <F3> :Grep<CR>
imap <F3> <esc><F3>
" F4 --- 全部退出
nmap <F4> :qall<cr>
imap <F4> <esc><F4>
" F5 --- 全部保存
nmap <silent> <F5> :wall<cr>
imap <F5> <esc><F5>
" F6 --- 代码补全 ( insert模式 )
imap <F6> <C-X><C-O>
" F7 --- 编译项目
nmap <silent> <F7> :call MyFun_make()<cr>
imap <F7> <esc><F7>
" F8 --- 重新编译项目
nmap <silent> <F8> :call MyFun_remake()<CR>
imap <F8> <esc><F8>
" F10 --- 生成当前目录的tags
nmap <silent> <F10> :call MyFun_mktag()<CR>
imap <F10> <esc><F10>
" <C-X><F10> --- 生成当前目录的cscope
nmap <C-X><F10> :call MyFun_mkcscope(".")<CR>
imap <C-X><F10> <esc><C-X><F10>
" <C-C><F10> --- 清除所有tags文件
nmap <C-C><F10> :call MyFun_cleantag(".")<CR>
imap <C-C><F10> <esc><C-X><F10>
" --- 清除屏幕高亮(搜索产生的)
nmap <C-A> :noh<cr>
imap <C-A> <esc><C-A>a
fun! MyFun_cleantag(p_dir)
if has("cscope")
silent! execute "cs kill -1"
endif
let dir = a:p_dir . "/"
exe ':!rm -f tags ' . dir . 'cscope.*'
endfun
fun! MyFun_mktag()
exe ':!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .'
endfun
fun! MyFun_mkcscope(p_dir)
if has("cscope")
silent! execute "cs kill -1"
else
return
endif
let dir = a:p_dir . "/"
if filereadable(dir."cscope.files")
let csfilesdeleted=delete(dir."cscope.files")
if(csfilesdeleted!=0)
echohl WarningMsg | echo "Fail to do cscope! I cannot delete the " . dir . "cscope.files" | echohl None
return
endif
endif
if filereadable(dir."cscope.out")
let csoutdeleted=delete(dir."cscope.out")
if(csoutdeleted!=0)
echohl WarningMsg | echo "Fail to do cscope! I cannot delete the " . dir . "cscope.out" | echohl None
return
endif
endif
silent! exe ':!rm -f ' .dir . 'cscope.*'
if(executable('cscope') && has("cscope") )
silent! execute '!find ' . dir . ' |grep -E ".(c|cc|cp|cpp|cxx|ipp|c++|h|h++|hh|hp|hpp|hxx|java)$" > ' . dir . 'cscope.files'
silent! execute "!cscope -bq -i " . dir . "cscope.files" . " -f " . dir . "cscope.out"
execute "normal :"
exe ':call MyFun_loadcscope("' . a:p_dir . '")'
endif
endfun
fun! MyFun_loadcscope(p_dir)
if has("cscope")
let dir = a:p_dir . "/"
if filereadable(dir."cscope.out")
execute "cs add " . dir . "cscope.out " . dir
endif
endif
endfun
fun! MyFun_check_tag()
if filereadable("tags")
silent! exe ':call MyFun_mktag()'
endif
if filereadable("cscope.out")
silent! exe ':call MyFun_mkcscope(".")'
endif
endfun
fun! MyFun_make()
exe ':wall'
exe ':make'
endfun
fun! MyFun_remake()
exe ':wall'
exe ':call MyFun_check_tag()'
exe ':make clean'
exe ':make'
endfun
command! -nargs=1 Csm :call MyFun_mkcscope(<q-args>)
command! -nargs=1 Csc :call MyFun_cleantag(<q-args>)
command! -nargs=1 Csl :call MyFun_loadcscope(<q-args>)
set tags=~/.vim/cpp_tags,~/.vim/c_tags,../../include/tags,../include/tags,./tags,../tags,../../tags
"set tags=~/.vim/ice_tags,~/.vim/bdb_tags,~/.vim/mongodb_tags,~/.vim/cpp_tags,~/.vim/c_tags,../../include/tags,../include/tags,./tags,../tags,../../tags
""""""""""""""""""""""""""""""
" taglist的配置
""""""""""""""""""""""""""""""
filetype on "文件类型自动检测
let Tlist_Ctags_Cmd = 'ctags' "ctags 执行文件
let Tlist_Show_One_File = 0 "0 显示多个文件 1 不同时显示多个文件的tag
let Tlist_File_Fold_Auto_Close = 1 "非当前文件,函数列表折叠隐藏
let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一个窗口,则退出vim
let Tlist_WinWidth = 40
nmap <F11> :Tlist<cr>
imap <F11> <esc><F11>a
""""""""""""""""""""""""""""""
" WinManager
""""""""""""""""""""""""""""""
let g:winManagerWindowLayout='FileExplorer|TagList' " 设置窗口布局
let g:winManagerWidth=40
nmap <F12> :WMToggle<cr>
imap <F12> <esc><F12>a
""""""""""""""""""""""""""""""
" MiniBufExplorer
""""""""""""""""""""""""""""""
let g:miniBufExplMapWindowNavArrows = 1 " 通过方向键切换窗口
let g:miniBufExplMapCTabSwitchBufs = 1 " 供过tab切换窗口
let g:miniBufExplModSelTarget = 1
let g:miniBufExplMapWindowNavVim = 1 " 通过h,j,k,l切换窗口 ( l没有发挥作用: 关闭金山词霸的热键 )
""""""""""""""""""""""""""""""
" OmniCppComplete
""""""""""""""""""""""""""""""
set nocp
filetype plugin on
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_ShowPrototypeInAbbr = 1 " 显示函数参数列表
let OmniCpp_MayCompleteDot = 1 " 输入 . 后自动补全
let OmniCpp_MayCompleteArrow = 1 " 输入 -> 后自动补全
let OmniCpp_MayCompleteScope = 1 " 输入 :: 后自动补全
let OmniCpp_ShowScopeInAbbr = 1 " 显示匹配项所在域,并移除缩略信息中最后一列
let OmniCpp_DefaultNamespaces = ["std","Emdp"]
" 自动关闭补全窗口
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,longest
" highlight Pmenu guibg=darkgrey guifg=black
" highlight PmenuSel guibg=blue guifg=white
""""""""""""""""""""""""""""""
" NERD_commenter的配置 无效?
""""""""""""""""""""""""""""""
"let NERDShutUp=1 " 支持单行和多行的选择
"map <C-C><C-H> ,c<space>
""""""""""""""""""""""""""""""
" DoxygenToolkit的配置
""""""""""""""""""""""""""""""
map fg : Dox<cr>
let g:DoxygenToolkit_authorName="yucheng"
let g:DoxygenToolkit_licenseTag="yucheng"
let g:DoxygenToolkit_undocTag="DOXIGEN_SKIP_BLOCK"
let g:DoxygenToolkit_briefTag_pre = "@brief "
let g:DoxygenToolkit_paramTag_pre = "@param "
let g:DoxygenToolkit_returnTag = "@return "
let g:DoxygenToolkit_briefTag_funcName = "no"
let g:DoxygenToolkit_maxFunctionProtoLines = 30
""""""""""""""""""""""""""""""
" grep.vim 的配置
""""""""""""""""""""""""""""""
let Grep_Default_Filelist = '*.h *.hp *.hpp *.hxx *.cpp *.ipp *.cxx *.cp *.cc *.c *.java'
"colorscheme darkblue
colorscheme desert
"colorscheme professional
"colorscheme Dark
"colorscheme shine
"colorscheme devcpp
"colorscheme wuye
"colorscheme borland
"colorscheme ron
"colorscheme blue
"colorscheme pablo
"colorscheme delek