给 GVIM 添加开发中常用的功能

来源:互联网 发布:淘宝网页设计 编辑:程序博客网 时间:2024/05/16 07:47
  • 首先在你的 vimrc 中添加如下配置
    • if(has("win32") || has("win95") || has("win64") || has("win16"))    let g:vimrc_iswindows=1else    let g:vimrc_iswindows=0endifautocmd BufEnter * lcd %:p:h
  • 确认安装了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")        else            let tagsdeleted=delete("./"."tags")        endif        if(tagsdeleted!=0)            echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None            return        endif    endif    if has("cscope")        silent! execute "cs kill -1"    endif    if filereadable("cscope.files")        if(g:iswindows==1)            let csfilesdeleted=delete(dir."\\"."cscope.files")        else            let csfilesdeleted=delete("./"."cscope.files")        endif        if(csfilesdeleted!=0)            echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None            return        endif    endif    if filereadable("cscope.out")        if(g:iswindows==1)            let csoutdeleted=delete(dir."\\"."cscope.out")        else            let csoutdeleted=delete("./"."cscope.out")        endif        if(csoutdeleted!=0)            echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None            return        endif    endif    if(executable('ctags'))        "silent! execute "!ctags -R --c-types=+p --fields=+S *"        silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."    endif    if(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"        else            silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"        endif        silent! execute "!cscope -b"        execute "normal :"        if filereadable("cscope.out")            execute "cs add cscope.out"        endif    endifendfunction

  • 使用 taglist.vim 实现了源代码结构和函数列表的展示

    • taglist.vim 下载地址 http://www.vim.org/scripts/script.php?script_id=273
    • 把taglist.vim放在plugin目录下后,在vimrc中添加如下的配置:
      • "进行Tlist的设置"TlistUpdate可以更新tagsmap <F3> :silent! Tlist<CR> "按下F3就可以呼出了let Tlist_Ctags_Cmd='ctags' "因为我们放在环境变量里,所以可以直接执行let Tlist_Use_Right_Window=1 "让窗口显示在右边,0的话就是显示在左边let Tlist_Show_One_File=0 "让taglist可以同时展示多个文件的函数列表,如果想只有1个,设置为1let Tlist_File_Fold_Auto_Close=1 "非当前文件,函数列表折叠隐藏let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动推出vimlet Tlist_Process_File_Always=0 "是否一直处理tags.1:处理;0:不处理。不是一直实时更新tags,因为没有必要let Tlist_Inc_Winwidth=0

  • 使用 omnicppcomplete.vim 实现写C/C++语言时自动补全

    • omnicppcomplete.vim 下载地址 http://www.vim.org/scripts/script.php?script_id=1520
    • 然后需要生成tags, 之前用F12映射的命令
    • 顺便说一下:omnicppcomplete会打开一个预览窗口来提示变量定义,如果不想要看到详细的信息的话,在vimrc中这样配置:
      • set completeopt=menu
    • 这样的话,在光标所在行上,按下一次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 目录下后,添加如下配置
      • "对NERD_commenter的设置let NERDShutUp=1

  • 使用 DoxygenToolkit.vim 由注释生成文档,并且能够快速生成函数标准注释

    • DoxygenToolkit.vim 下载地址 http://www.vim.org/scripts/script.php?script_id=987
    • 把 DoxygenToolkit.vim 放在plugin 目录下后,在 vimrc 中添加如下配置:
      • map fg : Dox<cr>let g:DoxygenToolkit_authorName="dantezhu"let g:DoxygenToolkit_licenseTag="My own license\<enter>"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
    • 读者可以按照需要将 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
0 0