码迷,mamicode.com
首页 > 系统相关 > 详细

Gvim 配置

时间:2015-03-19 16:10:13      阅读:832      评论:0      收藏:0      [点我收藏+]

标签:

1.安装vundle管理插件

  

sudo apt-get install vim
sudo apt-get install gvim
sudo apt-get install git


mkdir .vim
cd .vim
mkdir bundle
cd bundle
git clone https://github.com/gmarik/vundle.git

2.gvim配置文件

技术分享
  1 " =============================================================================
  2 "        << 判断操作系统是 Windows 还是 Linux 和判断是终端还是 Gvim >>
  3 " =============================================================================
  4  
  5 " -----------------------------------------------------------------------------
  6 "  < 判断操作系统是否是 Windows 还是 Linux >
  7 " -----------------------------------------------------------------------------
  8 let g:iswindows = 0
  9 let g:islinux = 0
 10 if(has("win32") || has("win64") || has("win95") || has("win16"))
 11     let g:iswindows = 1
 12 else
 13     let g:islinux = 1
 14 endif
 15  
 16 " -----------------------------------------------------------------------------
 17 "  < 判断是终端还是 Gvim >
 18 " -----------------------------------------------------------------------------
 19 if has("gui_running")
 20     let g:isGUI = 1
 21 else
 22     let g:isGUI = 0
 23 endif
 24  
 25  
 26 " =============================================================================
 27 "                          << 以下为软件默认配置 >>
 28 " =============================================================================
 29  
 30 " -----------------------------------------------------------------------------
 31 "  < Windows Gvim 默认配置> 做了一点修改
 32 " -----------------------------------------------------------------------------
 33 if (g:iswindows && g:isGUI)
 34     source $VIMRUNTIME/vimrc_example.vim
 35     source $VIMRUNTIME/mswin.vim
 36     behave mswin
 37     set diffexpr=MyDiff()
 38  
 39     function MyDiff()
 40         let opt = -a --binary 
 41         if &diffopt =~ icase | let opt = opt . -i  | endif
 42         if &diffopt =~ iwhite | let opt = opt . -b  | endif
 43         let arg1 = v:fname_in
 44         if arg1 =~   | let arg1 = " . arg1 . " | endif
 45         let arg2 = v:fname_new
 46         if arg2 =~   | let arg2 = " . arg2 . " | endif
 47         let arg3 = v:fname_out
 48         if arg3 =~   | let arg3 = " . arg3 . " | endif
 49         let eq = ‘‘
 50         if $VIMRUNTIME =~  
 51             if &sh =~ \<cmd
 52                 let cmd = "" . $VIMRUNTIME . \diff"
 53                 let eq = "
 54             else
 55                 let cmd = substitute($VIMRUNTIME,  , " , ‘‘) . \diff"
 56             endif
 57         else
 58             let cmd = $VIMRUNTIME . \diff
 59         endif
 60         silent execute ! . cmd .   . opt . arg1 .   . arg2 .  >  . arg3 . eq
 61     endfunction
 62 endif
 63  
 64 " -----------------------------------------------------------------------------
 65 "  < Linux Gvim/Vim 默认配置> 做了一点修改
 66 " -----------------------------------------------------------------------------
 67 if g:islinux
 68     set hlsearch        "高亮搜索
 69     set incsearch       "在输入要搜索的文字时,实时匹配
 70  
 71     " Uncomment the following to have Vim jump to the last position when
 72     " reopening a file
 73     if has("autocmd")
 74         au BufReadPost * if line("‘\"") > 1 && line("‘\"") <= line("$") | exe "normal! g‘\"" | endif
 75     endif
 76  
 77     if g:isGUI
 78         " Source a global configuration file if available
 79         if filereadable("/etc/vim/gvimrc.local")
 80             source /etc/vim/gvimrc.local
 81         endif
 82     else
 83         " This line should not be removed as it ensures that various options are
 84         " properly set to work with the Vim-related packages available in Debian.
 85         runtime! debian.vim
 86  
 87         " Vim5 and later versions support syntax highlighting. Uncommenting the next
 88         " line enables syntax highlighting by default.
 89         if has("syntax")
 90             syntax on
 91         endif
 92  
 93         set mouse=a                    " 在任何模式下启用鼠标
 94         set t_Co=256                   " 在终端启用256色
 95         set backspace=2                " 设置退格键可用
 96  
 97         " Source a global configuration file if available
 98         if filereadable("/etc/vim/vimrc.local")
 99             source /etc/vim/vimrc.local
100         endif
101     endif
102 endif
103  
104  
105 " =============================================================================
106 "                          << 以下为用户自定义配置 >>
107 " =============================================================================
108  
109 " -----------------------------------------------------------------------------
110 "  < Vundle 插件管理工具配置 >
111 " -----------------------------------------------------------------------------
112 " 用于更方便的管理vim插件,具体用法参考 :h vundle 帮助
113 " Vundle工具安装方法为在终端输入如下命令
114 " git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
115 " 如果想在 windows 安装就必需先安装 "git for window",可查阅网上资料
116  
117 set nocompatible                                      "禁用 Vi 兼容模式
118 filetype off                                          "禁用文件类型侦测
119  
120 if g:islinux
121     set rtp+=~/.vim/bundle/vundle/
122     call vundle#rc()
123 else
124     set rtp+=$VIM/vimfiles/bundle/vundle/
125     call vundle#rc($VIM/vimfiles/bundle/)
126 endif
127  
128 " 使用Vundle来管理插件,这个必须要有。
129 Bundle gmarik/vundle
130  
131 " 以下为要安装或更新的插件,不同仓库都有(具体书写规范请参考帮助)
132 Bundle a.vim
133 Bundle Align
134 Bundle jiangmiao/auto-pairs
135 Bundle bufexplorer.zip
136 Bundle ccvext.vim
137 Bundle cSyntaxAfter
138 Bundle ctrlpvim/ctrlp.vim
139 Bundle mattn/emmet-vim
140 Bundle Yggdroot/indentLine
141 Bundle vim-javacompleteex
142 Bundle Mark--Karkat
143 Bundle Shougo/neocomplcache.vim
144 Bundle scrooloose/nerdcommenter
145 Bundle scrooloose/nerdtree
146 Bundle OmniCppComplete
147 Bundle Lokaltog/vim-powerline
148 Bundle repeat.vim
149 Bundle msanders/snipmate.vim
150 Bundle wesleyche/SrcExpl
151 Bundle std_c.zip
152 Bundle tpope/vim-surround
153 Bundle scrooloose/syntastic
154 Bundle majutsushi/tagbar
155 Bundle taglist.vim
156 Bundle TxtBrowser
157 Bundle ZoomWin
158  
159 " -----------------------------------------------------------------------------
160 "  < 编码配置 >
161 " -----------------------------------------------------------------------------
162 " 注:使用utf-8格式后,软件与程序源码、文件路径不能有中文,否则报错
163 set encoding=utf-8                                    "设置gvim内部编码,默认不更改
164 set fileencoding=utf-8                                "设置当前文件编码,可以更改,如:gbk(同cp936)
165 set fileencodings=ucs-bom,utf-8,gbk,cp936,latin-1     "设置支持打开的文件的编码
166  
167 " 文件格式,默认 ffs=dos,unix
168 set fileformat=unix                                   "设置新(当前)文件的<EOL>格式,可以更改,如:dos(windows系统常用)
169 set fileformats=unix,dos,mac                          "给出文件的<EOL>格式类型
170  
171 if (g:iswindows && g:isGUI)
172     "解决菜单乱码
173     source $VIMRUNTIME/delmenu.vim
174     source $VIMRUNTIME/menu.vim
175  
176     "解决consle输出乱码
177     language messages zh_CN.utf-8
178 endif
179  
180 " -----------------------------------------------------------------------------
181 "  < 编写文件时的配置 >
182 " -----------------------------------------------------------------------------
183 filetype on                                           "启用文件类型侦测
184 filetype plugin on                                    "针对不同的文件类型加载对应的插件
185 filetype plugin indent on                             "启用缩进
186 set smartindent                                       "启用智能对齐方式
187 set expandtab                                         "将Tab键转换为空格
188 set tabstop=4                                         "设置Tab键的宽度,可以更改,如:宽度为2
189 set shiftwidth=4                                      "换行时自动缩进宽度,可更改(宽度同tabstop)
190 set smarttab                                          "指定按一次backspace就删除shiftwidth宽度
191 set foldenable                                        "启用折叠
192 set foldmethod=indent                                 "indent 折叠方式
193 " set foldmethod=marker                                "marker 折叠方式
194  
195 " 常规模式下用空格键来开关光标行所在折叠(注:zR 展开所有折叠,zM 关闭所有折叠)
196 nnoremap <space> @=((foldclosed(line(.)) < 0) ? zc : zo)<CR>
197  
198 " 当文件在外部被修改,自动更新该文件
199 set autoread
200  
201 " 常规模式下输入 cS 清除行尾空格
202 nmap cS :%s/\s\+$//g<CR>:noh<CR>
203  
204 " 常规模式下输入 cM 清除行尾 ^M 符号
205 nmap cM :%s/\r$//g<CR>:noh<CR>
206  
207 set ignorecase                                        "搜索模式里忽略大小写
208 set smartcase                                         "如果搜索模式包含大写字符,不使用 ‘ignorecase‘ 选项,只有在输入搜索模式并且打开 ‘ignorecase‘ 选项时才会使用
209 " set noincsearch                                       "在输入要搜索的文字时,取消实时匹配
210  
211 " Ctrl + K 插入模式下光标向上移动
212 imap <c-k> <Up>
213  
214 " Ctrl + J 插入模式下光标向下移动
215 imap <c-j> <Down>
216  
217 " Ctrl + H 插入模式下光标向左移动
218 imap <c-h> <Left>
219  
220 " Ctrl + L 插入模式下光标向右移动
221 imap <c-l> <Right>
222  
223 " 启用每行超过80列的字符提示(字体变蓝并加下划线),不启用就注释掉
224 au BufWinEnter * let w:m2=matchadd(Underlined, \%> . 80 . v.\+, -1)
225  
226 " -----------------------------------------------------------------------------
227 "  < 界面配置 >
228 " -----------------------------------------------------------------------------
229 set number                                            "显示行号
230 set laststatus=2                                      "启用状态栏信息
231 set cmdheight=2                                       "设置命令行的高度为2,默认为1
232 set cursorline                                        "突出显示当前行
233 " set guifont=YaHei_Consolas_Hybrid:h10                 "设置字体:字号(字体名称空格用下划线代替)
234 set nowrap                                            "设置不自动换行
235 set shortmess=atI                                     "去掉欢迎界面
236  
237 " 设置 gVim 窗口初始位置及大小
238 if g:isGUI
239     " au GUIEnter * simalt ~x                           "窗口启动时自动最大化
240     winpos 100 10                                     "指定窗口出现的位置,坐标原点在屏幕左上角
241     set lines=38 columns=120                          "指定窗口大小,lines为高度,columns为宽度
242 endif
243  
244 " 设置代码配色方案
245 if g:isGUI
246     colorscheme elflord                               "Gvim配色方案
247 else
248     colorscheme elflord                               "终端配色方案
249 endif
250  
251 " 显示/隐藏菜单栏、工具栏、滚动条,可用 Ctrl + F11 切换
252 if g:isGUI
253     set guioptions-=m
254     set guioptions-=T
255     set guioptions-=r
256     set guioptions-=L
257     nmap <silent> <c-F11> :if &guioptions =~# m <Bar>
258         \set guioptions-=m <Bar>
259         \set guioptions-=T <Bar>
260         \set guioptions-=r <Bar>
261         \set guioptions-=L <Bar>
262     \else <Bar>
263         \set guioptions+=m <Bar>
264         \set guioptions+=T <Bar>
265         \set guioptions+=r <Bar>
266         \set guioptions+=L <Bar>
267     \endif<CR>
268 endif
269  
270 " -----------------------------------------------------------------------------
271 "  < 编译、连接、运行配置 (目前只配置了C、C++、Java语言)>
272 " -----------------------------------------------------------------------------
273 " F9 一键保存、编译、连接存并运行
274 nmap <F9> :call Run()<CR>
275 imap <F9> <ESC>:call Run()<CR>
276  
277 " Ctrl + F9 一键保存并编译
278 nmap <c-F9> :call Compile()<CR>
279 imap <c-F9> <ESC>:call Compile()<CR>
280  
281 " Ctrl + F10 一键保存并连接
282 nmap <c-F10> :call Link()<CR>
283 imap <c-F10> <ESC>:call Link()<CR>
284  
285 let s:LastShellReturn_C = 0
286 let s:LastShellReturn_L = 0
287 let s:ShowWarning = 1
288 let s:Obj_Extension = .o
289 let s:Exe_Extension = .exe
290 let s:Class_Extension = .class
291 let s:Sou_Error = 0
292  
293 let s:windows_CFlags = gcc\ -fexec-charset=gbk\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o
294 let s:linux_CFlags = gcc\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o
295  
296 let s:windows_CPPFlags = g++\ -fexec-charset=gbk\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o
297 let s:linux_CPPFlags = g++\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o
298  
299 let s:JavaFlags = javac\ %
300  
301 func! Compile()
302     exe ":ccl"
303     exe ":update"
304     let s:Sou_Error = 0
305     let s:LastShellReturn_C = 0
306     let Sou = expand("%:p")
307     let v:statusmsg = ‘‘
308     if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"
309         let Obj = expand("%:p:r").s:Obj_Extension
310         let Obj_Name = expand("%:p:t:r").s:Obj_Extension
311         if !filereadable(Obj) || (filereadable(Obj) && (getftime(Obj) < getftime(Sou)))
312             redraw!
313             if expand("%:e") == "c"
314                 if g:iswindows
315                     exe ":setlocal makeprg=".s:windows_CFlags
316                 else
317                     exe ":setlocal makeprg=".s:linux_CFlags
318                 endif
319                 echohl WarningMsg | echo " compiling..."
320                 silent make
321             elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"
322                 if g:iswindows
323                     exe ":setlocal makeprg=".s:windows_CPPFlags
324                 else
325                     exe ":setlocal makeprg=".s:linux_CPPFlags
326                 endif
327                 echohl WarningMsg | echo " compiling..."
328                 silent make
329             endif
330             redraw!
331             if v:shell_error != 0
332                 let s:LastShellReturn_C = v:shell_error
333             endif
334             if g:iswindows
335                 if s:LastShellReturn_C != 0
336                     exe ":bo cope"
337                     echohl WarningMsg | echo " compilation failed"
338                 else
339                     if s:ShowWarning
340                         exe ":bo cw"
341                     endif
342                     echohl WarningMsg | echo " compilation successful"
343                 endif
344             else
345                 if empty(v:statusmsg)
346                     echohl WarningMsg | echo " compilation successful"
347                 else
348                     exe ":bo cope"
349                 endif
350             endif
351         else
352             echohl WarningMsg | echo ""Obj_Name"is up to date"
353         endif
354     elseif expand("%:e") == "java"
355         let class = expand("%:p:r").s:Class_Extension
356         let class_Name = expand("%:p:t:r").s:Class_Extension
357         if !filereadable(class) || (filereadable(class) && (getftime(class) < getftime(Sou)))
358             redraw!
359             exe ":setlocal makeprg=".s:JavaFlags
360             echohl WarningMsg | echo " compiling..."
361             silent make
362             redraw!
363             if v:shell_error != 0
364                 let s:LastShellReturn_C = v:shell_error
365             endif
366             if g:iswindows
367                 if s:LastShellReturn_C != 0
368                     exe ":bo cope"
369                     echohl WarningMsg | echo " compilation failed"
370                 else
371                     if s:ShowWarning
372                         exe ":bo cw"
373                     endif
374                     echohl WarningMsg | echo " compilation successful"
375                 endif
376             else
377                 if empty(v:statusmsg)
378                     echohl WarningMsg | echo " compilation successful"
379                 else
380                     exe ":bo cope"
381                 endif
382             endif
383         else
384             echohl WarningMsg | echo ""class_Name"is up to date"
385         endif
386     else
387         let s:Sou_Error = 1
388         echohl WarningMsg | echo " please choose the correct source file"
389     endif
390     exe ":setlocal makeprg=make"
391 endfunc
392  
393 func! Link()
394     call Compile()
395     if s:Sou_Error || s:LastShellReturn_C != 0
396         return
397     endif
398     if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"
399         let s:LastShellReturn_L = 0
400         let Sou = expand("%:p")
401         let Obj = expand("%:p:r").s:Obj_Extension
402         if g:iswindows
403             let Exe = expand("%:p:r").s:Exe_Extension
404             let Exe_Name = expand("%:p:t:r").s:Exe_Extension
405         else
406             let Exe = expand("%:p:r")
407             let Exe_Name = expand("%:p:t:r")
408         endif
409         let v:statusmsg = ‘‘
410         if filereadable(Obj) && (getftime(Obj) >= getftime(Sou))
411             redraw!
412             if !executable(Exe) || (executable(Exe) && getftime(Exe) < getftime(Obj))
413                 if expand("%:e") == "c"
414                     setlocal makeprg=gcc\ -o\ %<\ %<.o
415                     echohl WarningMsg | echo " linking..."
416                     silent make
417                 elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"
418                     setlocal makeprg=g++\ -o\ %<\ %<.o
419                     echohl WarningMsg | echo " linking..."
420                     silent make
421                 endif
422                 redraw!
423                 if v:shell_error != 0
424                     let s:LastShellReturn_L = v:shell_error
425                 endif
426                 if g:iswindows
427                     if s:LastShellReturn_L != 0
428                         exe ":bo cope"
429                         echohl WarningMsg | echo " linking failed"
430                     else
431                         if s:ShowWarning
432                             exe ":bo cw"
433                         endif
434                         echohl WarningMsg | echo " linking successful"
435                     endif
436                 else
437                     if empty(v:statusmsg)
438                         echohl WarningMsg | echo " linking successful"
439                     else
440                         exe ":bo cope"
441                     endif
442                 endif
443             else
444                 echohl WarningMsg | echo ""Exe_Name"is up to date"
445             endif
446         endif
447         setlocal makeprg=make
448     elseif expand("%:e") == "java"
449         return
450     endif
451 endfunc
452  
453 func! Run()
454     let s:ShowWarning = 0
455     call Link()
456     let s:ShowWarning = 1
457     if s:Sou_Error || s:LastShellReturn_C != 0 || s:LastShellReturn_L != 0
458         return
459     endif
460     let Sou = expand("%:p")
461     if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"
462         let Obj = expand("%:p:r").s:Obj_Extension
463         if g:iswindows
464             let Exe = expand("%:p:r").s:Exe_Extension
465         else
466             let Exe = expand("%:p:r")
467         endif
468         if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou)
469             redraw!
470             echohl WarningMsg | echo " running..."
471             if g:iswindows
472                 exe ":!%<.exe"
473             else
474                 if g:isGUI
475                     exe ":!gnome-terminal -x bash -c ‘./%<; echo; echo 请按 Enter 键继续; read‘"
476                 else
477                     exe ":!clear; ./%<"
478                 endif
479             endif
480             redraw!
481             echohl WarningMsg | echo " running finish"
482         endif
483     elseif expand("%:e") == "java"
484         let class = expand("%:p:r").s:Class_Extension
485         if getftime(class) >= getftime(Sou)
486             redraw!
487             echohl WarningMsg | echo " running..."
488             if g:iswindows
489                 exe ":!java %<"
490             else
491                 if g:isGUI
492                     exe ":!gnome-terminal -x bash -c ‘java %<; echo; echo 请按 Enter 键继续; read‘"
493                 else
494                     exe ":!clear; java %<"
495                 endif
496             endif
497             redraw!
498             echohl WarningMsg | echo " running finish"
499         endif
500     endif
501 endfunc
502  
503  
504 " -----------------------------------------------------------------------------
505 "  < 在浏览器中预览 Html 或 PHP 文件 >
506 " -----------------------------------------------------------------------------
507 " 修改前请先通读此模块,明白了再改以避免错误
508  
509 " F5 加浏览器名称缩写调用浏览器预览,启用前先确定有安装相应浏览器,并在下面的配置好其安装目录
510 if g:iswindows
511     "以下为只支持Windows系统的浏览器
512  
513     " 调用系统IE浏览器预览,如果已卸载可将其注释
514     nmap <F5>ie :call ViewInBrowser("ie")<cr>
515     imap <F5>ie <ESC>:call ViewInBrowser("ie")<cr>
516  
517     " 调用IETester(IE测试工具)预览,如果有安装可取消注释
518     " nmap <F5>ie6 :call ViewInBrowser("ie6")<cr>
519     " imap <F5>ie6 <ESC>:call ViewInBrowser("ie6")<cr>
520     " nmap <F5>ie7 :call ViewInBrowser("ie7")<cr>
521     " imap <F5>ie7 <ESC>:call ViewInBrowser("ie7")<cr>
522     " nmap <F5>ie8 :call ViewInBrowser("ie8")<cr>
523     " imap <F5>ie8 <ESC>:call ViewInBrowser("ie8")<cr>
524     " nmap <F5>ie9 :call ViewInBrowser("ie9")<cr>
525     " imap <F5>ie9 <ESC>:call ViewInBrowser("ie9")<cr>
526     " nmap <F5>ie10 :call ViewInBrowser("ie10")<cr>
527     " imap <F5>ie10 <ESC>:call ViewInBrowser("ie10")<cr>
528     " nmap <F5>iea :call ViewInBrowser("iea")<cr>
529     " imap <F5>iea <ESC>:call ViewInBrowser("iea")<cr>
530 elseif g:islinux
531     "以下为只支持Linux系统的浏览器
532     "暂未配置,待有时间再弄了
533 endif
534  
535 "以下为支持Windows与Linux系统的浏览器
536  
537 " 调用Firefox浏览器预览,如果有安装可取消注释
538 " nmap <F5>ff :call ViewInBrowser("ff")<cr>
539 " imap <F5>ff <ESC>:call ViewInBrowser("ff")<cr>
540  
541 " 调用Maxthon(遨游)浏览器预览,如果有安装可取消注释
542 " nmap <F5>ay :call ViewInBrowser("ay")<cr>
543 " imap <F5>ay <ESC>:call ViewInBrowser("ay")<cr>
544  
545 " 调用Opera浏览器预览,如果有安装可取消注释
546 " nmap <F5>op :call ViewInBrowser("op")<cr>
547 " imap <F5>op <ESC>:call ViewInBrowser("op")<cr>
548  
549 " 调用Chrome浏览器预览,如果有安装可取消注释
550 " nmap <F5>cr :call ViewInBrowser("cr")<cr>
551 " imap <F5>cr <ESC>:call ViewInBrowser("cr")<cr>
552  
553 " 浏览器调用函数
554 function! ViewInBrowser(name)
555     if expand("%:e") == "php" || expand("%:e") == "html"
556         exe ":update"
557         if g:iswindows
558             "获取要预览的文件路径,并将路径中的‘\‘替换为‘/‘,同时将路径文字的编码转换为gbk(同cp936)
559             let file = iconv(substitute(expand("%:p"), \‘, /, "g"), "utf-8", "gbk")
560  
561             "浏览器路径设置,路径中使用‘/‘斜杠,更改路径请更改双引号里的内容
562             "下面只启用了系统IE浏览器,如需启用其它的可将其取消注释(得先安装,并配置好安装路径),也可按需增减
563             let SystemIE = "C:/progra~1/intern~1/iexplore.exe"  "系统自带IE目录
564             " let IETester = "F:/IETester/IETester.exe"           "IETester程序目录(可按实际更改)
565             " let Chrome = "F:/Chrome/Chrome.exe"                 "Chrome程序目录(可按实际更改)
566             " let Firefox = "F:/Firefox/Firefox.exe"              "Firefox程序目录(可按实际更改)
567             " let Opera = "F:/Opera/opera.exe"                    "Opera程序目录(可按实际更改)
568             " let Maxthon = "C:/Progra~2/Maxthon/Bin/Maxthon.exe" "Maxthon程序目录(可按实际更改)
569  
570             "本地虚拟服务器设置,我测试的是phpStudy2014,可根据自己的修改,更改路径请更改双引号里的内容
571             let htdocs ="F:/phpStudy2014/WWW/"                  "虚拟服务器地址或目录(可按实际更改)
572             let url = "localhost"                               "虚拟服务器网址(可按实际更改)
573         elseif g:islinux
574             "暂时还没有配置,有时间再弄了。
575         endif
576  
577         "浏览器调用缩写,可根据实际增减,注意,上面浏览器路径中没有定义过的变量(等号右边为变量)不能出现在下面哟(可将其注释或删除)
578         let l:browsers = {}                             "定义缩写字典变量,此行不能删除或注释
579         " let l:browsers["cr"] = Chrome                   "Chrome浏览器缩写
580         " let l:browsers["ff"] = Firefox                  "Firefox浏览器缩写
581         " let l:browsers["op"] = Opera                    "Opera浏览器缩写
582         " let l:browsers["ay"] = Maxthon                  "遨游浏览器缩写
583         let l:browsers["ie"] = SystemIE                 "系统IE浏览器缩写
584         " let l:browsers["ie6"] = IETester."-ie6"         "调用IETESTER工具以IE6预览缩写(变量加参数)
585         " let l:browsers["ie7"] = IETester."-ie7"         "调用IETESTER工具以IE7预览缩写(变量加参数)
586         " let l:browsers["ie8"] = IETester."-ie8"         "调用IETESTER工具以IE8预览缩写(变量加参数)
587         " let l:browsers["ie9"] = IETester."-ie9"         "调用IETESTER工具以IE9预览缩写(变量加参数)
588         " let l:browsers["ie10"] = IETester."-ie10"       "调用IETESTER工具以IE10预览缩写(变量加参数)
589         " let l:browsers["iea"] = IETester."-al"          "调用IETESTER工具以支持的所有IE版本预览缩写(变量加参数)
590  
591         if stridx(file, htdocs) == -1   "文件不在本地虚拟服务器目录,则直接预览(但不能解析PHP文件)
592            exec ":silent !start ". l:browsers[a:name] ." file://" . file
593         else    "文件在本地虚拟服务器目录,则调用本地虚拟服务器解析预览(先启动本地虚拟服务器)
594             let file = substitute(file, htdocs, "http://".url."/", "g")    "转换文件路径为虚拟服务器网址路径
595             exec ":silent !start ". l:browsers[a:name] file
596         endif
597     else
598         echohl WarningMsg | echo " please choose the correct source file"
599     endif
600 endfunction
601  
602 " -----------------------------------------------------------------------------
603 "  < 其它配置 >
604 " -----------------------------------------------------------------------------
605 set writebackup                             "保存文件前建立备份,保存成功后删除该备份
606 set nobackup                                "设置无备份文件
607 " set noswapfile                              "设置无临时文件
608 " set vb t_vb=                                "关闭提示音
609  
610  
611 " =============================================================================
612 "                          << 以下为常用插件配置 >>
613 " =============================================================================
614  
615 " -----------------------------------------------------------------------------
616 "  < a.vim 插件配置 >
617 " -----------------------------------------------------------------------------
618 " 用于切换C/C++头文件
619 " :A     ---切换头文件并独占整个窗口
620 " :AV    ---切换头文件并垂直分割窗口
621 " :AS    ---切换头文件并水平分割窗口
622  
623 " -----------------------------------------------------------------------------
624 "  < Align 插件配置 >
625 " -----------------------------------------------------------------------------
626 " 一个对齐的插件,用来——排版与对齐代码,功能强大,不过用到的机会不多
627  
628 " -----------------------------------------------------------------------------
629 "  < auto-pairs 插件配置 >
630 " -----------------------------------------------------------------------------
631 " 用于括号与引号自动补全,不过会与函数原型提示插件echofunc冲突
632 " 所以我就没有加入echofunc插件
633  
634 " -----------------------------------------------------------------------------
635 "  < BufExplorer 插件配置 >
636 " -----------------------------------------------------------------------------
637 " 快速轻松的在缓存中切换(相当于另一种多个文件间的切换方式)
638 " <Leader>be 在当前窗口显示缓存列表并打开选定文件
639 " <Leader>bs 水平分割窗口显示缓存列表,并在缓存列表窗口中打开选定文件
640 " <Leader>bv 垂直分割窗口显示缓存列表,并在缓存列表窗口中打开选定文件
641  
642 " -----------------------------------------------------------------------------
643 "  < ccvext.vim 插件配置 >
644 " -----------------------------------------------------------------------------
645 " 用于对指定文件自动生成tags与cscope文件并连接
646 " 如果是Windows系统, 则生成的文件在源文件所在盘符根目录的.symbs目录下(如: X:\.symbs\)
647 " 如果是Linux系统, 则生成的文件在~/.symbs/目录下
648 " 具体用法可参考www.vim.org中此插件的说明
649 " <Leader>sy 自动生成tags与cscope文件并连接
650 " <Leader>sc 连接已存在的tags与cscope文件
651  
652 " -----------------------------------------------------------------------------
653 "  < cSyntaxAfter 插件配置 >
654 " -----------------------------------------------------------------------------
655 " 高亮括号与运算符等
656 au! BufRead,BufNewFile,BufEnter *.{c,cpp,h,java,javascript} call CSyntaxAfter()
657  
658 " -----------------------------------------------------------------------------
659 "  < ctrlp.vim 插件配置 >
660 " -----------------------------------------------------------------------------
661 " 一个全路径模糊文件,缓冲区,最近最多使用,... 检索插件;详细帮助见 :h ctrlp
662 " 常规模式下输入:Ctrl + p 调用插件
663  
664 " -----------------------------------------------------------------------------
665 "  < emmet-vim(前身为Zen coding) 插件配置 >
666 " -----------------------------------------------------------------------------
667 " HTML/CSS代码快速编写神器,详细帮助见 :h emmet.txt
668  
669 " -----------------------------------------------------------------------------
670 "  < indentLine 插件配置 >
671 " -----------------------------------------------------------------------------
672 " 用于显示对齐线,与 indent_guides 在显示方式上不同,根据自己喜好选择了
673 " 在终端上会有屏幕刷新的问题,这个问题能解决有更好了
674 " 开启/关闭对齐线
675 nmap <leader>il :IndentLinesToggle<CR>
676  
677 " 设置Gvim的对齐线样式
678 if g:isGUI
679     let g:indentLine_char = ""
680     let g:indentLine_first_char = ""
681 endif
682  
683 " 设置终端对齐线颜色,如果不喜欢可以将其注释掉采用默认颜色
684 let g:indentLine_color_term = 239
685  
686 " 设置 GUI 对齐线颜色,如果不喜欢可以将其注释掉采用默认颜色
687 " let g:indentLine_color_gui = ‘#A4E57E‘
688  
689 " -----------------------------------------------------------------------------
690 "  < vim-javacompleteex(也就是 javacomplete 增强版)插件配置 >
691 " -----------------------------------------------------------------------------
692 " java 补全插件
693  
694 " -----------------------------------------------------------------------------
695 "  < Mark--Karkat(也就是 Mark) 插件配置 >
696 " -----------------------------------------------------------------------------
697 " 给不同的单词高亮,表明不同的变量时很有用,详细帮助见 :h mark.txt
698  
699 " " -----------------------------------------------------------------------------
700 " "  < MiniBufExplorer 插件配置 >
701 " " -----------------------------------------------------------------------------
702 " " 快速浏览和操作Buffer
703 " " 主要用于同时打开多个文件并相与切换
704  
705 " " let g:miniBufExplMapWindowNavArrows = 1     "用Ctrl加方向键切换到上下左右的窗口中去
706 " let g:miniBufExplMapWindowNavVim = 1        "用<C-k,j,h,l>切换到上下左右的窗口中去
707 " let g:miniBufExplMapCTabSwitchBufs = 1      "功能增强(不过好像只有在Windows中才有用)
708 " "                                            <C-Tab> 向前循环切换到每个buffer上,并在但前窗口打开
709 " "                                            <C-S-Tab> 向后循环切换到每个buffer上,并在当前窗口打开
710  
711 " 在不使用 MiniBufExplorer 插件时也可用<C-k,j,h,l>切换到上下左右的窗口中去
712 noremap <c-k> <c-w>k
713 noremap <c-j> <c-w>j
714 noremap <c-h> <c-w>h
715 noremap <c-l> <c-w>l
716  
717 " -----------------------------------------------------------------------------
718 "  < neocomplcache 插件配置 >
719 " -----------------------------------------------------------------------------
720 " 关键字补全、文件路径补全、tag补全等等,各种,非常好用,速度超快。
721 let g:neocomplcache_enable_at_startup = 1     "vim 启动时启用插件
722 " let g:neocomplcache_disable_auto_complete = 1 "不自动弹出补全列表
723 " 在弹出补全列表后用 <c-p> 或 <c-n> 进行上下选择效果比较好
724  
725 " -----------------------------------------------------------------------------
726 "  < nerdcommenter 插件配置 >
727 " -----------------------------------------------------------------------------
728 " 我主要用于C/C++代码注释(其它的也行)
729 " 以下为插件默认快捷键,其中的说明是以C/C++为例的,其它语言类似
730 " <Leader>ci 以每行一个 /* */ 注释选中行(选中区域所在行),再输入则取消注释
731 " <Leader>cm 以一个 /* */ 注释选中行(选中区域所在行),再输入则称重复注释
732 " <Leader>cc 以每行一个 /* */ 注释选中行或区域,再输入则称重复注释
733 " <Leader>cu 取消选中区域(行)的注释,选中区域(行)内至少有一个 /* */
734 " <Leader>ca 在/*...*/与//这两种注释方式中切换(其它语言可能不一样了)
735 " <Leader>cA 行尾注释
736 let NERDSpaceDelims = 1                     "在左注释符之后,右注释符之前留有空格
737  
738 " -----------------------------------------------------------------------------
739 "  < nerdtree 插件配置 >
740 " -----------------------------------------------------------------------------
741 " 有目录村结构的文件浏览插件
742  
743 " 常规模式下输入 F2 调用插件
744 nmap <F2> :NERDTreeToggle<CR>
745  
746 " -----------------------------------------------------------------------------
747 "  < omnicppcomplete 插件配置 >
748 " -----------------------------------------------------------------------------
749 " 用于C/C++代码补全,这种补全主要针对命名空间、类、结构、共同体等进行补全,详细
750 " 说明可以参考帮助或网络教程等
751 " 使用前先执行如下 ctags 命令(本配置中可以直接使用 ccvext 插件来执行以下命令)
752 " ctags -R --c++-kinds=+p --fields=+iaS --extra=+q
753 " 我使用上面的参数生成标签后,对函数使用跳转时会出现多个选择
754 " 所以我就将--c++-kinds=+p参数给去掉了,如果大侠有什么其它解决方法希望不要保留呀
755 set completeopt=menu                        "关闭预览窗口
756  
757 " -----------------------------------------------------------------------------
758 "  < powerline 插件配置 >
759 " -----------------------------------------------------------------------------
760 " 状态栏插件,更好的状态栏效果
761  
762 " -----------------------------------------------------------------------------
763 "  < repeat 插件配置 >
764 " -----------------------------------------------------------------------------
765 " 主要用"."命令来重复上次插件使用的命令
766  
767 " -----------------------------------------------------------------------------
768 "  < snipMate 插件配置 >
769 " -----------------------------------------------------------------------------
770 " 用于各种代码补全,这种补全是一种对代码中的词与代码块的缩写补全,详细用法可以参
771 " 考使用说明或网络教程等。不过有时候也会与 supertab 插件在补全时产生冲突,如果大
772 " 侠有什么其它解决方法希望不要保留呀
773  
774 " -----------------------------------------------------------------------------
775 "  < SrcExpl 插件配置 >
776 " -----------------------------------------------------------------------------
777 " 增强源代码浏览,其功能就像Windows中的"Source Insight"
778 nmap <F3> :SrcExplToggle<CR>                "打开/闭浏览窗口
779  
780 " -----------------------------------------------------------------------------
781 "  < std_c 插件配置 >
782 " -----------------------------------------------------------------------------
783 " 用于增强C语法高亮
784  
785 " 启用 // 注视风格
786 let c_cpp_comments = 0
787  
788 " -----------------------------------------------------------------------------
789 "  < surround 插件配置 >
790 " -----------------------------------------------------------------------------
791 " 快速给单词/句子两边增加符号(包括html标签),缺点是不能用"."来重复命令
792 " 不过 repeat 插件可以解决这个问题,详细帮助见 :h surround.txt
793  
794 " -----------------------------------------------------------------------------
795 "  < Syntastic 插件配置 >
796 " -----------------------------------------------------------------------------
797 " 用于保存文件时查检语法
798  
799 " -----------------------------------------------------------------------------
800 "  < Tagbar 插件配置 >
801 " -----------------------------------------------------------------------------
802 " 相对 TagList 能更好的支持面向对象
803  
804 " 常规模式下输入 tb 调用插件,如果有打开 TagList 窗口则先将其关闭
805 nmap tb :TlistClose<CR>:TagbarToggle<CR>
806  
807 let g:tagbar_width=30                       "设置窗口宽度
808 " let g:tagbar_left=1                         "在左侧窗口中显示
809  
810 " -----------------------------------------------------------------------------
811 "  < TagList 插件配置 >
812 " -----------------------------------------------------------------------------
813 " 高效地浏览源码, 其功能就像vc中的workpace
814 " 那里面列出了当前文件中的所有宏,全局变量, 函数名等
815  
816 " 常规模式下输入 tl 调用插件,如果有打开 Tagbar 窗口则先将其关闭
817 nmap tl :TagbarClose<CR>:Tlist<CR>
818  
819 let Tlist_Show_One_File=1                   "只显示当前文件的tags
820 " let Tlist_Enable_Fold_Column=0              "使taglist插件不显示左边的折叠行
821 let Tlist_Exit_OnlyWindow=1                 "如果Taglist窗口是最后一个窗口则退出Vim
822 let Tlist_File_Fold_Auto_Close=1            "自动折叠
823 let Tlist_WinWidth=30                       "设置窗口宽度
824 let Tlist_Use_Right_Window=1                "在右侧窗口中显示
825  
826 " -----------------------------------------------------------------------------
827 "  < txtbrowser 插件配置 >
828 " -----------------------------------------------------------------------------
829 " 用于文本文件生成标签与与语法高亮(调用TagList插件生成标签,如果可以)
830 au BufRead,BufNewFile *.txt setlocal ft=txt
831  
832 " -----------------------------------------------------------------------------
833 "  < ZoomWin 插件配置 >
834 " -----------------------------------------------------------------------------
835 " 用于分割窗口的最大化与还原
836 " 常规模式下按快捷键 <c-w>o 在最大化与还原间切换
837  
838 " =============================================================================
839 "                          << 以下为常用工具配置 >>
840 " =============================================================================
841  
842 " -----------------------------------------------------------------------------
843 "  < cscope 工具配置 >
844 " -----------------------------------------------------------------------------
845 " 用Cscope自己的话说 - "你可以把它当做是超过频的ctags"
846 if has("cscope")
847     "设定可以使用 quickfix 窗口来查看 cscope 结果
848     set cscopequickfix=s-,c-,d-,i-,t-,e-
849     "使支持用 Ctrl+]  和 Ctrl+t 快捷键在代码间跳转
850     set cscopetag
851     "如果你想反向搜索顺序设置为1
852     set csto=0
853     "在当前目录中添加任何数据库
854     if filereadable("cscope.out")
855         cs add cscope.out
856     "否则添加数据库环境中所指出的
857     elseif $CSCOPE_DB != ""
858         cs add $CSCOPE_DB
859     endif
860     set cscopeverbose
861     "快捷键设置
862     nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
863     nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
864     nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
865     nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
866     nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
867     nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
868     nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
869     nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
870 endif
871  
872 " -----------------------------------------------------------------------------
873 "  < ctags 工具配置 >
874 " -----------------------------------------------------------------------------
875 " 对浏览代码非常的方便,可以在函数,变量之间跳转等
876 set tags=./tags;                            "向上级目录递归查找tags文件(好像只有在Windows下才有用)
877  
878 " -----------------------------------------------------------------------------
879 "  < gvimfullscreen 工具配置 > 请确保已安装了工具
880 " -----------------------------------------------------------------------------
881 " 用于 Windows Gvim 全屏窗口,可用 F11 切换
882 " 全屏后再隐藏菜单栏、工具栏、滚动条效果更好
883 if (g:iswindows && g:isGUI)
884     nmap <F11> <Esc>:call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0)<CR>
885 endif
886  
887 " -----------------------------------------------------------------------------
888 "  < vimtweak 工具配置 > 请确保以已装了工具
889 " -----------------------------------------------------------------------------
890 " 这里只用于窗口透明与置顶
891 " 常规模式下 Ctrl + Up(上方向键) 增加不透明度,Ctrl + Down(下方向键) 减少不透明度,<Leader>t 窗口置顶与否切换
892 if (g:iswindows && g:isGUI)
893     let g:Current_Alpha = 255
894     let g:Top_Most = 0
895     func! Alpha_add()
896         let g:Current_Alpha = g:Current_Alpha + 10
897         if g:Current_Alpha > 255
898             let g:Current_Alpha = 255
899         endif
900         call libcallnr("vimtweak.dll","SetAlpha",g:Current_Alpha)
901     endfunc
902     func! Alpha_sub()
903         let g:Current_Alpha = g:Current_Alpha - 10
904         if g:Current_Alpha < 155
905             let g:Current_Alpha = 155
906         endif
907         call libcallnr("vimtweak.dll","SetAlpha",g:Current_Alpha)
908     endfunc
909     func! Top_window()
910         if  g:Top_Most == 0
911             call libcallnr("vimtweak.dll","EnableTopMost",1)
912             let g:Top_Most = 1
913         else
914             call libcallnr("vimtweak.dll","EnableTopMost",0)
915             let g:Top_Most = 0
916         endif
917     endfunc
918  
919     "快捷键设置
920     nmap <c-up> :call Alpha_add()<CR>
921     nmap <c-down> :call Alpha_sub()<CR>
922     nmap <leader>t :call Top_window()<CR>
923 endif
924  
925 " =============================================================================
926 "                          << 以下为常用自动命令配置 >>
927 " =============================================================================
928  
929 " 自动切换目录为当前编辑文件所在目录
930 au BufRead,BufNewFile,BufEnter * cd %:p:h
931  
932 " =============================================================================
933 "                     << windows 下解决 Quickfix 乱码问题 >>
934 " =============================================================================
935 " windows 默认编码为 cp936,而 Gvim(Vim) 内部编码为 utf-8,所以常常输出为乱码
936 " 以下代码可以将编码为 cp936 的输出信息转换为 utf-8 编码,以解决输出乱码问题
937 " 但好像只对输出信息全部为中文才有满意的效果,如果输出信息是中英混合的,那可能
938 " 不成功,会造成其中一种语言乱码,输出信息全部为英文的好像不会乱码
939 " 如果输出信息为乱码的可以试一下下面的代码,如果不行就还是给它注释掉
940  
941 " if g:iswindows
942 "     function QfMakeConv()
943 "         let qflist = getqflist()
944 "         for i in qflist
945 "            let i.text = iconv(i.text, "cp936", "utf-8")
946 "         endfor
947 "         call setqflist(qflist)
948 "      endfunction
949 "      au QuickfixCmdPost make call QfMakeConv()
950 " endif
951  
952 " =============================================================================
953 "                          << 其它 >>
954 " =============================================================================
955 " 注:上面配置中的"<Leader>"在本软件中设置为"\"键(引号里的反斜杠),如<Leader>t
956 " 指在常规模式下按"\"键加"t"键,这里不是同时按,而是先按"\"键后按"t"键,间隔在一
957 " 秒内,而<Leader>cs是先按"\"键再按"c"又再按"s"键;如要修改"<leader>"键,可以把
958 " 下面的设置取消注释,并修改双引号中的键为你想要的,如修改为逗号键。
959  
960 "
.gvimrc

3.在gvim中下载插件

:BundleInstall

基本设置完成

 

具体设置可见

http://www.cnblogs.com/youxia/p/linux002.html

Gvim 配置

标签:

原文地址:http://www.cnblogs.com/py100/p/4350604.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!