详细解决方案
给 GVIM 添加开发中常用的功能
热度:89 发布时间:2024-01-16 21:17:50.0
- 首先在你的 vimrc 中添加如下配置
- 确认安装了ctags和cscope,并且确认这两个可执行程序所在的目录已经放进环境变量里面,然后继续在 vimrc 中添加如下配置
map <F12> :call Do_CsTag()<CR>
nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR>
nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR>
nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR>
function Do_CsTag()let dir = getcwd()if filereadable("tags")if(g:iswindows==1)let tagsdeleted=delete(dir."\\"."tags")elselet tagsdeleted=delete("./"."tags")endifif(tagsdeleted!=0)echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl Nonereturnendifendifif has("cscope")silent! execute "cs kill -1"endifif filereadable("cscope.files")if(g:iswindows==1)let csfilesdeleted=delete(dir."\\"."cscope.files")elselet csfilesdeleted=delete("./"."cscope.files")endifif(csfilesdeleted!=0)echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl Nonereturnendifendifif filereadable("cscope.out")if(g:iswindows==1)let csoutdeleted=delete(dir."\\"."cscope.out")elselet csoutdeleted=delete("./"."cscope.out")endifif(csoutdeleted!=0)echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl Nonereturnendifendifif(executable('ctags'))"silent! execute "!ctags -R --c-types=+p --fields=+S *"silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."endifif(executable('cscope') && has("cscope") )if(g:iswindows!=1)silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"elsesilent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"endifsilent! execute "!cscope -b"execute "normal :"if filereadable("cscope.out")execute "cs add cscope.out"endifendif
endfunction
- 使用 taglist.vim 实现了源代码结构和函数列表的展示
-
- taglist.vim 下载地址 http://www.vim.org/scripts/script.php?script_id=273
- 把taglist.vim放在plugin目录下后,在vimrc中添加如下的配置:
- 使用 omnicppcomplete.vim 实现写C/C++语言时自动补全
-
- omnicppcomplete.vim 下载地址 http://www.vim.org/scripts/script.php?script_id=1520
- 然后需要生成tags, 之前用F12映射的命令
- 顺便说一下:omnicppcomplete会打开一个预览窗口来提示变量定义,如果不想要看到详细的信息的话,在vimrc中这样配置:
- 这样的话,在光标所在行上,按下一次ctrl+h是注释,再按下一次是取消注释。
- 而其内建的指令,cm是多行注释,类似C++的/**/,,cu是取消注释。
- 使用 NERD_commenter.vim 生成注释
-
- NERD_commenter.vim 下载地址 http://www.vim.org/scripts/script.php?script_id=1218
- 把 NERD_commenter.vim 放在 plugin 目录下后,添加如下配置
- 使用 DoxygenToolkit.vim 由注释生成文档,并且能够快速生成函数标准注释
-
- DoxygenToolkit.vim 下载地址 http://www.vim.org/scripts/script.php?script_id=987
- 把 DoxygenToolkit.vim 放在plugin 目录下后,在 vimrc 中添加如下配置:
- 读者可以按照需要将 DoxygenToolkit_authorName设置成为自己的名字,OK,这样标准格式的代码注释就出来啦。
- 使用 a.vim 实现 .cpp文件和.h文件快速切换
-
- a.vim 下载地址:http://www.vim.org/scripts/script.php?script_id=31
- 不需要任何配置
- 以上文章整理自 http://www.vimer.cn/2009/10/%E6%8A%8Avim%E6%89%93%E9%80%A0%E6%88%90%E4%B8%80%E4%B8%AA%E7%9C%9F%E6%AD%A3%E7%9A%84ide2.html 和 http://www.vimer.cn/2009/10/%E6%8A%8Avim%E6%89%93%E9%80%A0%E6%88%90%E4%B8%80%E4%B8%AA%E7%9C%9F%E6%AD%A3%E7%9A%84ide3.html