爱悠闲 > Windows Gvim工程配置

Windows Gvim工程配置

分类: gvim  |  作者: augusdi 相关  |  发布日期 : 2015-02-20  |  热度 : 44°


1. 安装gvim

下在安装gvim后,默认路径为C:\Program Files\Vim,即$VIM变量保存的值

其中:

vim72为gvim 系统默认目录,

vimfiles 为gvim 用户设定目录

2. 安装插件

下载插件放在C:\ProgramFiles\Vim\vimfiles\plugin目录下

可以下载自己喜欢的vim配色放在C:\Program Files\Vim\vimfiles\colors目录中

然后在自己的vimrc中指定colorscheme 配置名称

3. 安装cscope、ctags及所用到的linux命令,及环境变量设置

因为在我们的vimrc配置中用到一些linux下的命令,如cp,cd ,find 等,还有cscope与 ctags命令,所以要把linux下的一些命令,给”拷贝”(不是直接复制过来哟~)出来。

因为linux这些命令如果要在window运行,需要一些环境库,所以我们直接从cywin把这些命令拷贝出来,而cscope与ctags可以从官方下载,编译成window版。如图:


我们在C:\ProgramFiles\Vim中建个文件夹,命名为VIM_NEED_EXE(你可以随便取名~)

然后把上图中的这些命令拷贝到此文件夹下,因为一会我们要用到的gvim中,要用到这些命令,所以我们好要把这些命令加到windows环境变量中,需要注意的一点是,windows中也有find,sort命令,而二者是有差别的,为了使用我们的find,sort命令能第一个匹配(就是使用linux下这个find命令,而不是windows下的,二者有区别,具体区别去百度查一查),我们有一个技巧:把我们的命令的环境变量放在前面,这样能首次匹配。

如下图,为我的window环境变量设置目录(别告诉我你找不到,自己去百度查去~)

其中PATH为用户(我的是hr)的程序的查找位置。下面还有个“系统变量”,其中有个Path,这是所有用户的默认系统执行路径设置。打个比方:如果你要运行暴风影音程序,那么,先到“系统变量”Path中查找一下又无暴风影音的可执行程序,如果没有,再到用户的PATH中查找。即PATH 〉Path。

所以我们要将C:\ProgramFiles\Vim\VIM_NEED_EXE 加入到系统PATH中,并且要放在最前面,因为如下图,我在cmd中输入path后,先打印出系统PATH,然后才是用户的path

如果我们把C:\ProgramFiles\Vim\VIM_NEED_EXE放在path中或PATH中,会首先匹配windows 的find 或sort命令。


4. _Vimrc及工程vim插件配置

 

__vimrc文件

我们保持__vimrc文件基本不变,只是在最后一行,加入source$VIM/my_vimrc_win.vim

引入我们自己的vimrc配置文件

set nocompatible

source $VIMRUNTIME/vimrc_example.vim

source $VIMRUNTIME/mswin.vim

behave mswin

 

set diffexpr=MyDiff()

function MyDiff()

  letopt = '-a --binary '

  if&diffopt =~ 'icase' | let opt = opt . '-i ' | endif

  if&diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif

  letarg1 = v:fname_in

  ifarg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif

  letarg2 = v:fname_new

  ifarg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif

  letarg3 = v:fname_out

  ifarg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif

  leteq = ''

  if$VIMRUNTIME =~ ' '

   if &sh =~ '\<cmd'

     let cmd = '""' . $VIMRUNTIME . '\diff"'

     let eq = '"'

   else

     let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'

   endif

 else

   let cmd = $VIMRUNTIME . '\diff'

 endif

 silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' .arg3 . eq

endfunction

 

source $VIM/my_vimrc_win.vim

_my_vimrc_win.vim文件

我们自己的vimrc配置文件,关于每句话的含义,我们不一一解释,只把一些关键的解释一下

set nu

filetype plugin indent on

set autoindent

set tabstop=4

set shiftwidth=4     " 缩进宽度

set mouse=a                 "使用鼠标

set nowrap                   "不自动换行

set nohls                "不高亮显示查找结果

set nobackup         " 不生成备份文件

set guioptions-=T   " 隐藏工具栏

colorscheme lucius

 

"set encoding=utf-8

"set fileencoding=utf-8

"set fileencodings=utf-8

"set termencoding=utf-8

 

"Set mapleader

let mapleader = "," “前导符号

 

" 启用代码折叠

autocmd FileType c,cpp  setl fdm=indent | setl nofen

 

" 打开taglist

map <silent> <F9>:TlistToggle<cr>

 

""""""""""""""""""""""""""""""

" netrw setting

""""""""""""""""""""""""""""""

let g:netrw_winsize = 30

nmap <silent> <leader>fe:Sexplore!<cr>

 

""""""""""""""""""""""""""""""

" BufExplorer

""""""""""""""""""""""""""""""

let g:bufExplorerDefaultHelp=0       " Do not show default help.

let g:bufExplorerShowRelativePath=1  " Show relative paths.

let g:bufExplorerSortBy='mru'        " Sort by most recently used.

let g:bufExplorerSplitRight=0        " Split left.

let g:bufExplorerSplitVertical=1     " Split vertically.

let g:bufExplorerSplitVertSize = 30  " Splitwidth

let g:bufExplorerUseCurrentWindow=1  " Open in new window.

autocmd BufWinEnter

Buf List 
setlnonumber

 

""""""""""""""""""""""""""""""

" winManager setting

""""""""""""""""""""""""""""""

let g:winManagerWindowLayout ="BufExplorer,FileExplorer|TagList"

let g:winManagerWidth = 30

let g:defaultExplorer = 0

nmap <silent> <leader>wf:FirstExplorerWindow<cr>

nmap <silent> <leader>wb:BottomExplorerWindow<cr>

nmap <silent> <leader>wm:WMToggle<cr>

map <silent> <F8>:WMToggle<cr>

 

""""""""""""""""""""""""""""""

" lookupfile setting

""""""""""""""""""""""""""""""

let g:LookupFile_MinPatLength = 2               "最少输入2个字符才开始查找

"let g:LookupFile_PreserveLastPattern= 0       "0表示不保存上次查找的字符串

let g:LookupFile_PreservePatternHistory =1     "保存查找历史

let g:LookupFile_AlwaysAcceptFirst = 1          "回车打开第一个匹配项目

let g:LookupFile_AllowNewFiles = 0              "不允许创建不存在的文件

iffilereadable("./filenametags")               "设置tag文件的名字

       letg:LookupFile_TagExpr = '"./filenametags"'

endif

nmap <silent> <leader>lt:LUTags<cr>

nmap <silent> <leader>lb:LUBufs<cr>

nmap <silent> <leader>lw:LUWalk<cr>

 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" ctags setting

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" configure tags

set tags+=$VIM/tags/gtk

" mapping

map <C-F9> :callUpdateTagsCscope()<CR><CR>

inoremap <expr> <CR>       pumvisible()?"\<C-Y>":"\<CR>"

"inoremap <expr><C-J>     pumvisible()?"\<PageDown>\<C-N>\<C-P>":"\<C-X><C-O>"

"inoremap <expr><C-K>     pumvisible()?"\<PageUp>\<C-P>\<C-N>":"\<C-K>"

inoremap <expr> <C-J>     pumvisible()?"\<C-N>":"\<C-X><C-O>"

inoremap <expr> <C-K>     pumvisible()?"\<C-P>":"\<C-K>"

inoremap <expr> <C-U>     pumvisible()?"\<C-E>":"\<C-U>"

 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" OmniCppComplete setting

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

let OmniCpp_NamespaceSearch = 1

let OmniCpp_GlobalScopeSearch = 1

let OmniCpp_ShowAccess = 1

let OmniCpp_ShowPrototypeInAbbr = 1      " show function parameters

let OmniCpp_MayCompleteDot = 1             " autocomplete after .

let OmniCpp_MayCompleteArrow = 1  " autocomplete after ->

let OmniCpp_MayCompleteScope = 1   " autocomplete after ::

let OmniCpp_DefaultNamespaces =["std", "_GLIBCXX_STD"]

" automatically open and close thepopup menu / preview window

au CursorMovedI,InsertLeave * ifpumvisible() == 0|silent! pclose|endif

setcompleteopt=menuone,menu,longest,preview

 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" cscope setting

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

if has("cscope")

       set csto=1

       set cst

endif

 

nmap <C-\>s :cs find s<C-R>=expand("<cword>")<CR><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>

nmap <C-\>t :cs find t<C-R>=expand("<cword>")<CR><CR>

nmap <C-\>e :cs find e<C-R>=expand("<cword>")<CR><CR>

nmap <C-\>f :cs find f<C-R>=expand("<cfile>")<CR><CR>

nmap <C-\>i :cs find i^<C-R>=expand("<cfile>")<CR>$<CR>

nmap <C-\>d :cs find d<C-R>=expand("<cword>")<CR><CR>

 

""""""""""""""""""""""""""""""

" mark setting

""""""""""""""""""""""""""""""

nmap <silent> <leader>hl<Plug>MarkSet

vmap <silent> <leader>hl<Plug>MarkSet

nmap <silent> <leader>hh<Plug>MarkClear

vmap <silent> <leader>hh<Plug>MarkClear

nmap <silent> <leader>hr<Plug>MarkRegex

vmap <silent> <leader>hr<Plug>MarkRegex

 

""""""""""""""""""""""""""""""

" showmarks setting

""""""""""""""""""""""""""""""

" Enable ShowMarks

let showmarks_enable = 1

" Show which marks

let showmarks_include ="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

" Ignore help, quickfix, non-modifiablebuffers

let showmarks_ignore_type = "hqm"

" Hilight lower & upper marks

let showmarks_hlline_lower = 1

let showmarks_hlline_upper = 1

 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" quickfix setting

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

autocmd FileType c,cpp  map <buffer><leader><space> :w<cr>:make<cr>

nmap <leader>cc :cc<cr>

nmap <leader>cl :cl<cr>

nmap <leader>cn :cn<cr>

nmap <leader>cp :cp<cr>

nmap <leader>cw :cw 10<cr>

 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" preview-window setting

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

nmap <leader>pc :pclose<cr>

 

function! InitProject()

       iffilereadable(g:project_vim)

              execute"source " . g:project_vim “加载我们的工程project.vim

       endif

       execute"set path+=" . g:project_dir . "**"

       execute"set tags+=" . g:project_dir . "tags" “加入工程目录的tags文件

 

       setnocsverb

       iffilereadable(g:project_dir . "cscope.out")

              execute"cs add " . g:project_dir . "cscope.out" “加入工程目录的cscope.out文件

       elseif$CSCOPE_DB != ""

              csadd $CSCOPE_DB

       endif

       setcsverb

 

       execute"cd " . g:work_dir

endfunction

 

function! UpdateTagsCscope() “重要的函数,建议看看,在初始化时调用

       wall                             " Write allchanged buffers.

       execute"cd " . g:project_dir “切换到我们的工程目录,这个变量是我们自定义的。在project.vim中定义的let g:project_dir ="E:\GVIM_PROJECT\"

       !ctags-R --c++-kinds=+p --fields=+iaS --extra=+q . “生成ctags

 

       setnocsverb

       cskill -1

       setcsverb

 

       execute"cd " . g:work_dir

       !find. -type f | grep -E "(\.h|\.c|\.hpp|\.cpp|\.js)$" > cscope.files  “查找指定文件类型,生成列表,也可以不find,用cscope –R生成,但是不能指定类型

       !cscope–bq “生成cscope.out文件和cscope.po.out文件(加b参数的话,查找时候能快速一些)

 

       execute"!move cscope.* " . g:project_dir

 

       callInitProject()

endfunction

 

let g:project_dir = "./"

let g:work_dir = "./"

let g:project_vim = $VIM.\\project.vim “在初始化InitProject()函数中,会加载我们的工程project.vim

 

" execute project relatedconfiguration

call InitProject()

 

"----copy from easwy----

 

" Platform

function! MySys()

  ifhas("win32")

   return "windows"

 else

    return "linux"

 endif

endfunction

 

function! SwitchToBuf(filename)

   "let fullfn = substitute(a:filename, "^\\~/", $HOME ."/", "")

   " find in current tab

   let bufwinnr = bufwinnr(a:filename)

   if bufwinnr != -1

       exec bufwinnr . "wincmd w"

       return

   else

       " find in each tab

       tabfirst

       let tab = 1

       while tab <= tabpagenr("$")

           let bufwinnr = bufwinnr(a:filename)

           if bufwinnr != -1

                exec "normal " . tab. "gt"

               exec bufwinnr ."wincmd w"

                return

           endif

           tabnext

           let tab = tab + 1

       endwhile

       " not exist, new tab

       exec "tabnew " . a:filename

   endif

endfunction

 

"Fast edit vimrc

if MySys() == 'linux'

   "Fast reloading of the .vimrc

   map <silent> <leader>ss :source ~/.vimrc<cr>

   "Fast editing of .vimrc

   map <silent> <leader>ee :callSwitchToBuf("~/.vimrc")<cr>

   "When .vimrc is edited, reload it

   autocmd! bufwritepost .vimrc source ~/.vimrc

elseif MySys() == 'windows'

   " Set helplang

   set helplang=cn

   "Fast reloading of the _vimrc

   map <silent> <leader>ss :source $VIM/_vimrc<cr>

   "Fast editing of _vimrc

   map <silent> <leader>ee :call SwitchToBuf("$VIM/_vimrc")<cr>

   "When _vimrc is edited, reload it

   autocmd! bufwritepost _vimrc source $VIM/_vimrc

endif

 

" For windows version

if MySys() == 'windows'

   source $VIMRUNTIME/mswin.vim

   behave mswin

endif

project.vim文件

工程路径的配置文件

" 设置工程路径和工作路径。工程路径需使用绝对路径,并且不能使用~符号

 letg:project_dir = "E:\\GVIM_PROJECT\\" “工程目录,用于生成cscope与tags

nmap cdopl :cd E:\GVIM_PROJECT\PROJECT_1\src<CR><CR>

“normal模式直接按下cdopl,切换到工程指定目录

 

5. 享受vim

插入模式Ctrl_I 查找函数匹配,ctrl_n ctrl_p上下浏览

目录文件查找 ,(前导)+lw

http://www.aiuxian.com/article/p-2273322.html