=======================================
安装vim相关软件
=======================================
1 编译安装VIM7.4
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:winManagerhelptags ~/.vim/doc" -c "q"
map
,c
"这样的话,在光标所在行上,按下一次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 shift
缩进所表示的空格数
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
‘zc‘ :
‘zo‘)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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
imap
nmap
:cs find g
imap
nmap
:cs find d
imap
nmap
:cs find c
imap
nmap
:cs find t
imap
nmap
:cs find e
imap
nmap
:cs find f
imap
nmap
:cs find i
imap
endif " if
has("cscope")
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
快捷键设置
" nmap
是command模式, imap
是insert模式
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
F3 --- 查找
nmap
:Grep
imap
"
F4 --- 全部退出
nmap
:qall
imap
"
F5 --- 全部保存
nmap
imap
"
F6 --- 代码补全 ( insert模式 )
imap
" F7 ---
编译项目
nmap
imap
" F8 ---
重新编译项目
nmap
imap
" F10 ---
生成当前目录的tags
nmap
MyFun_mktag()
imap
"
nmap
imap
"
nmap
imap
"
--- 清除屏幕高亮(搜索产生的)
nmap
imap
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|cs)美元符" > ‘ . 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(
command! -nargs=1 Csc :call
MyFun_cleantag(
command! -nargs=1 Csl :call
MyFun_loadcscope(
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
:Tlist
imap
""""""""""""""""""""""""""""""
"
WinManager
""""""""""""""""""""""""""""""
let
g:winManagerWindowLayout=‘FileExplorer|TagList‘ " 设置窗口布局
let
g:winManager"""""""""""""""""""""""""""""
"
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
""""""""""""""""""""""""""""""
"
DoxygenToolkit的配置
""""""""""""""""""""""""""""""
map fg :
Dox
let g:DoxygenToolkit_authorName="yucheng"
let
g:DoxygenToolkit_licenseTag="yucheng"
let
g:DoxygenToolkit_undocTag="DOXIGEN_SKIP_BLOCK"
let
g:DoxygenToolkit_briefTag_pre = "@brief\t"
let g:DoxygenToolkit_paramTag_pre
= "@param\t"
let g:DoxygenToolkit_returnTag = "@return\t"
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‘
"colorscheme
darkblue
colorscheme desert
"colorscheme professional
"colorscheme
Dark
"colorscheme shine
"colorscheme devcpp
"colorscheme
wuye
"colorscheme borland
"colorscheme ron
"colorscheme
blue
"colorscheme pablo
"colorscheme delek
把VIM打造成IDE,布布扣,bubuko.com