Windows 下 用Gvim(gvim)建立IDE编程环境

来源:互联网 发布:缩小手机屏幕显示软件 编辑:程序博客网 时间:2024/04/28 20:50
1.软件的准备

(a)gvim73.exe 地址 http://www.sfr-fresh.com/windows/misc/gvim73.zip/ (不能下载用GG)
(b)ec57w32.zip 地址 http://prdownloads.sourceforge.net/ctags/ec57w32.zip
(c)cscope 地址 http://download.famouswhy.com/cscope_for_windows/
(d)taglist_45.zip 地址 http://www.vim.org/scripts/download_script.php?src_id=7701
(e)winmanager.zip 地址 http://www.vim.org/scripts/download_script.php?src_id=754
(f)bufexplorer    地址 http://www.vim.org/scripts/script.php?script_id=42
(g)a.vim 地址 http://www.vim.org/scripts/download_script.php?src_id=7218
(i)visualmark.vim 地址 http://www.vim.org/scripts/download_script.php?src_id=4700
(j) showfunc.vim    地址 http://vimer.cn/wp-content/uploads/2009/10/showfunc.vim (拷贝里面的内存保存为 showfunc.vim)


a.安装gvim73。
运行gvim73.exe,选择完全安装(Full),我的安装目录是默认的 D:/Program Files/Vim
安装完成后,包括了文件夹vim73和文件夹vimfiles,以及脚本_vimrc。上个图过过瘾

graphic

可以按照gvim73中文帮助手册,怎么样安装自己gg 吧,一般不要安装吧,学en的好机会。

先编译一下 _vimrc 配置文件显示一下高亮

语法高亮。

首先,编辑_vimrc文件加入以下内容:
set nu! "设置行号
colorscheme desert "设置配色方案
syntax enable
syntax on     "打开高亮

这些设置使得gvim可以显示行号,并使用了desert配色方案,而且打开了语法高亮功能(用不同颜色显示注释、关键字、字符串等)。
我们还可以让函数名也高亮起来,在 D:/Program Files/Vim/vim73/syntax下找到 c.vim 和 cpp.vim,分别添加以下内容:
syn match cFunction "/<[a-zA-Z_][a-zA-Z_0-9]*/>[^()]*)("me=e-2
syn match cFunction "/<[a-zA-Z_][a-zA-Z_0-9]*/>/s*("me=e-1
hi cFunction gui=NONE guifg=#B5A1FF
重新打开gvim,效果如下:

graphic


b.安装函数跳转的插件 ctags.exe

我再gvim 安装目录下面建了个文件夹 tools ,解压出文件后把 ctags.exe 放到文件夹中,把 D:/Program Files/Vim/tools 路径加到环境变量
中。

并编辑_vimrc文件,添加以下内容:
set tags=tags;
set autochdir

上面的; 是必须的。

在CMD 窗口中 执行 ctags --help 如果能正常运行证明安装成功。先这么安装,后面会用到。

c.安装cscope 插件,这个安装和 ctags 安装是一样的,下载后把程序放在 tools 目录下

在_vimrc 文件中加入一下内容:

let g:CODEPATH="F://kanghuawen//code//TIBS_HOME"

cs add F:/kanghuawen/code/TIBS_HOME/cscope.out

if(has("win32") || has("win95") || has("win64") || has("win16")) "判定当前操作系统类型
    let g:iswindows=1
else
    let g:iswindows=0
endif

autocmd BufEnter * lcd %:p:h
set nocompatible "不要vim模仿vi模式,建议设置,否则会有很多不兼容的问题


"上面这几行在最前面加

"设置tags 和 更新tags

map :call Do_CsTag()
nmap s :cs find s =expand(""):copen
nmap g :cs find g =expand("")
nmap c :cs find c =expand(""):copen
nmap t :cs find t =expand(""):copen
nmap e :cs find e =expand(""):copen
nmap f :cs find f =expand(""):copen
nmap i :cs find i ^=expand("")$:copen
nmap d :cs find d =expand(""):copen
function Do_CsTag()
    "let dir = getcwd()
     let dir = g:CODEPATH
    
     "进入代码的根目录
     execute "cd F://kanghuawen//code//TIBS_HOME"
    
         
    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
    endif
endfunction

"解决 cscope 和 ctags 的冲突

if has("cscope")
    set cscopequickfix=s-,c-,d-,i-,t-,e-
    set csto=0
    set cst
    set csverb
endif


加好后按F12,就会生成 tags cscope.files cscope.out 三个文件
graphic

在 setFileInfo 函数下 按 ctrl+] 就会跳转到函数的定义处,cscope 看另外的介绍
graphic


d e f .安装窗口管理插件

将taglist_45 winmanager bufexplorer .zip解压,解压后包含一个doc文件夹和一个plugin文件夹,将其中内容分别复制到D:/Program Files/Vim/vim73下的doc及plugin中。
在_vimrc文件中加入以下内容:

"进行Tlist的设置
"TlistUpdate可以更新tags
let Tlist_Use_Right_Window=0 "让窗口显示在右边,0的话就是显示在左边
let Tlist_Show_One_File=1 "让taglist可以同时展示多个文件的函数列表,如果想只有1个,设置为1
let Tlist_File_Fold_Auto_Close=0 "非当前文件,函数列表折叠隐藏
let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动推出vim
"是否一直处理tags.1:处理;0:不处理
let Tlist_Process_File_Always=0 "不是一直实时更新tags,因为没有必要
let Tlist_Inc_Winwidth=0


let g:winManagerWindowLayout='BufExplorer,FileExplorer|TagList'
let g:winManagerWidth = 30
let g:defaultExplorer = 0
nmap :FirstExplorerWindow
nmap :BottomExplorerWindow
nmap wm :WMToggle
let g:bufExplorerMinHeight=15

set completeopt=menu

用gvim打开代码文件,normal状态下输入命令"wm",窗口如下

graphic

再次输入"wm"时这两个窗口会关闭。
在下面这个窗口内包含两个窗口 可以使用 ctrl+n 去切换,自己摸索吧.

graphic


g 快速切换头文件/源文件。
将a.vim复制到 D:/Program Files/Vim/vim73/plugin,
用gvim打开源码文件后,在c/h文件中切换,可以通过输入:A实现。

i 高亮的书签。
将visualmark.vim复制到D:/Program Files/Vim/vim73/plugin。
用gvim打开源码文件,将光标定位在需要添加书签的地方,按下ctrl+F2,即添加了书签。

graphic


j 安装 showfunc.vim   

截图如下:

graphic

这个插件实现了按下fd,就可以提示当前光标所在函数的定义,另外还实现了当输入'('时,会自动匹配tags,展示函数的定义原型。

只需要把这个插件放到plugin下就行,不需要配置。

备注:_vimrc 全部配置

let g:CODEPATH="F://kanghuawen//code//TIBS_HOME"

cs add F:/kanghuawen/code/TIBS_HOME/cscope.out

if(has("win32") || has("win95") || has("win64") || has("win16")) "判定当前操作系统类型
    let g:iswindows=1
else
    let g:iswindows=0
endif

autocmd BufEnter * lcd %:p:h
set nocompatible "不要vim模仿vi模式,建议设置,否则会有很多不兼容的问题

"设置行号
set nu!
"设置颜色方案
colorscheme desert
"开启高亮
syntax enable
syntax on

"设置tags
set tags=tags;
set autochdir

if has("autocmd")
    filetype plugin indent on "根据文件进行缩进
    augroup vimrcEx
        au!
        autocmd FileType text setlocal textwidth=78
        autocmd BufReadPost *
                    / if line("'/"") > 1 && line("'/"") <= line("$") |
                    / exe "normal! g`/"" |
                    / endif
    augroup END
else
    "智能缩进,相应的有cindent,官方说autoindent可以支持各种文件的缩进,但是效果会比只支持C/C++的cindent效果会差一点,但笔者并没有看出来
    set autoindent " always set autoindenting on
endif " has("autocmd")
set tabstop=4 "让一个tab等于4个空格
set vb t_vb=
set nowrap "不自动换行
set hlsearch "高亮显示结果
set incsearch "在输入要搜索的文字时,vim会实时匹配
set backspace=indent,eol,start whichwrap+=<,>,[,] "允许退格键的使用
if(g:iswindows==1) "允许鼠标的使用
    "防止linux终端下无法拷贝
    if has('mouse')
        set mouse=a
    endif
    au GUIEnter * simalt ~x
endif
"字体的设置
set guifont=Bitstream_Vera_Sans_Mono:h9:cANSI "记住空格用下划线代替哦
set gfw=幼圆:h10:cGB2312


"设置tags 和 更新tags

map :call Do_CsTag()
nmap s :cs find s =expand(""):copen
nmap g :cs find g =expand("")
nmap c :cs find c =expand(""):copen
nmap t :cs find t =expand(""):copen
nmap e :cs find e =expand(""):copen
nmap f :cs find f =expand(""):copen
nmap i :cs find i ^=expand("")$:copen
nmap d :cs find d =expand(""):copen
function Do_CsTag()
    "let dir = getcwd()
     let dir = g:CODEPATH
    
     execute "cd F://kanghuawen//code//TIBS_HOME"
    
         
    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
    endif
endfunction


"进行Tlist的设置
"TlistUpdate可以更新tags
let Tlist_Use_Right_Window=0 "让窗口显示在右边,0的话就是显示在左边
let Tlist_Show_One_File=1 "让taglist可以同时展示多个文件的函数列表,如果想只有1个,设置为1
let Tlist_File_Fold_Auto_Close=0 "非当前文件,函数列表折叠隐藏
let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动推出vim
"是否一直处理tags.1:处理;0:不处理
let Tlist_Process_File_Always=0 "不是一直实时更新tags,因为没有必要
let Tlist_Inc_Winwidth=0


let g:winManagerWindowLayout='BufExplorer,FileExplorer|TagList'
let g:winManagerWidth = 30
let g:defaultExplorer = 0
nmap :FirstExplorerWindow
nmap :BottomExplorerWindow
nmap wm :WMToggle
let g:bufExplorerMinHeight=15

set completeopt=menu


if has("cscope")
    set cscopequickfix=s-,c-,d-,i-,t-,e-
    set csto=0
    set cst
    set csverb
endif
  
原创粉丝点击