配置文件(vimrc)

  1. set nocompatible
  2. set nu!
  3. set cursorline
  4. colorscheme murphy
  5. " vim 自身命令行模式智能补全
  6. set wildmenu
  7. " 开启文件类型侦测
  8. filetype on
  9. " 总是显示状态栏
  10. " set laststatus=2
  11. " 高亮显示当前行/列
  12. set cursorline
  13. " set cursorcolumn
  14.  
  15. colorscheme jellybeans
  16. "Toggle Menu and Toolbar 隐藏菜单,按f2出现
  17. "Toggle Menu and Toolbar
  18. set guioptions-=m
  19. set guioptions-=T
  20. map <silent> <F2> :if &guioptions =~# 'T' <Bar>
  21. \set guioptions-=T <Bar>
  22. \set guioptions-=m <bar>
  23. \else <Bar>
  24. \set guioptions+=T <Bar>
  25. \set guioptions+=m <Bar>
  26. \endif<CR>
  27. "
  28. "设置文件的代码形式
  29. set encoding=utf-8
  30. set termencoding=utf-8
  31. set fileencoding=utf-8
  32. set fileencodings=ucs-bom,utf-8,chinese,cp936
  33. "vim的菜单乱码解决: "
  34. source $VIMRUNTIME/delmenu.vim
  35. source $VIMRUNTIME/menu.vim
  36. "vim提示信息乱码的解决
  37. language messages zh_CN.utf-8
  38.  
  39. "max size 启动时窗口最大化
  40. au GUIEnter * simalt ~x
  41.  
  42. source $VIMRUNTIME/vimrc_example.vim
  43. source $VIMRUNTIME/mswin.vim
  44. behave mswin
  45.  
  46. set diffexpr=MyDiff()
  47. function MyDiff()
  48. let opt = '-a --binary '
  49. if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  50. if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  51. let arg1 = v:fname_in
  52. if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  53. let arg2 = v:fname_new
  54. if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  55. let arg3 = v:fname_out
  56. if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  57. let eq = ''
  58. if $VIMRUNTIME =~ ' '
  59. if &sh =~ '\<cmd'
  60. let cmd = '""' . $VIMRUNTIME . '\diff"'
  61. let eq = '"'
  62. else
  63. let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
  64. endif
  65. else
  66. let cmd = $VIMRUNTIME . '\diff'
  67. endif
  68. silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
  69. endfunction

  

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

  

环境:Windows7 旗舰版

1、安装Gvim7.4 : 下载地址http://www.vim.org/download.php#pc

2、安装中文帮助:vimcdoc-1.8.0-setup.exe 地址http://vimcdoc.sourceforge.net/

会自动识别gvim的安装路径,

安装完后,gvim菜单中文出现乱码,在_vimrcset文件中增加:

" 配置多语言环境,解决中文乱码问题

if has("multi_byte") 
    " UTF-8 编码 
    set encoding=utf-8 
    set termencoding=utf-8 
    set formatoptions+=mM 
    set fencs=utf-8,gbk 
    if v:lang =~? '^/(zh/)/|/(ja/)/|/(ko/)' 
        set ambiwidth=double 
    endif 
    if has("win32") 
        source $VIMRUNTIME/delmenu.vim 
        source $VIMRUNTIME/menu.vim 
        language messages zh_CN.utf-8 
    endif 
else 
    echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte" 
endif

输入:help,显示中文帮助,说明安装成功:

3、设置语法高亮

编辑安装目录下的_vimrc文件(例如:我的在D:\Program Files\Vim)

加入以下内容:

set nu!

colorscheme desert 
     syntax enable 
     syntax on

再打开gvim,打开一个源代码文件:

这些设置使得gvim可以显示行号,并使用了desert配色方案,而且打开了语法高亮功能(用不同颜色显示注释、关键字、字符串等)。 
我们还可以让函数名也高亮起来,

这里对C、C++的代码进行配置:在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,效果如下:

 

4、程序中跳转

将ec57w32.zip解压,在解压后将文件夹中的ctags.exe复制到D:\ProgramFiles\Vim\vim73下,并编辑_vimrc文件,添加以下内容: 
set tags=tags; 
set autochdir

然后将D:\ProgramFiles\Vim\vim73加到环境变量的path中。在需要查看的源代码目录下执行命令ctags -R;然后再用gvim打开源代码文件:

 

按住“CTRL”键,点击对应的函数名或“CTRL+]”,会自动跳转到函数的定义部分,“CTRL+T”则返回;

5、源代码分析工具 taglist

将taglist_45.zip解压,解压后包含一个doc文件夹和一个plugin文件夹,将其中内容分别复制到d:\Program Files\Vim\vim73下的doc及plugin中。 
在_vimrc文件中加入以下内容: 
let Tlist_Show_One_File=1 
let Tlist_Exit_OnlyWindow=1

 

用gvim打开代码文件(已生成过tags文件),输入:Tlist,TagList窗口即出现在左侧。再输入:

:Tlist,左侧栏消失;左侧栏列出了当前文件中的所有宏,  全局变量,  函数名等,  在查看代码时用这个窗口总揽全局,  切换位置相当方便

 

 

6、文件浏览组件 WinManager

winmanager.zip 地址http://www.vim.org/scripts/download_script.php?src_id=754

将winmanager.zip解压和拷贝,解压后包含一个doc文件夹和一个plugin文件夹,将其中内容分别复制到d:\Program Files\Vim\vim73下的doc及plugin中

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

let g:winManagerWindowLayout='FileExplorer|TagList' 
nmap wm :WMToggle<cr>

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

左上角是浏览文件的窗口,左下角的是TagList窗口;

7、多文档编辑

minibufexpl.vim 地址http://www.vim.org/scripts/download_script.php?src_id=3640

解压后将将minibufexpl.vim复制到d:\Program Files\Vim\vim73\plugin,在_vimrc中添加:

let g:miniBufExplMapCTabSwitchBufs=1 
let g:miniBufExplMapWindowsNavVim=1 
let g:miniBufExplMapWindowNavArrows=1

用GVIM打开多个源代码文件后,如图:

ctrl+Tab,切换到前一个buffer,并在当前窗口打开文件; 
ctrl+shift+Tab,切换到后一个buffer,并在当前窗口打开文件; 
ctrl+箭头键,可以切换到上下左右窗口中; 
ctrl+h,j,k,l,切换到上下左右的窗口中。

 

8、在工程中快速查找

grep.vim 地址http://www.vim.org/scripts/download_script.php?src_id=7645

解压后把grep.vim文件拷贝到d:\Program Files\Vim\vim73\plugin,在_vimrc中添加:

nnoremap <silent> <F3> :Grep<CR>

因为windows下是不带grep的,需要下载Grep for Windows http://gnuwin32.sourceforge.net/packages/grep.htm

下载后在环境变量中增加grep的路径;

用gvim打开一个源代码文件,光标选择需要查找的内容,按F3,确定要查找的内容和搜索范围,gvim会在弹出的QuickFix窗口中列出所有符合条件的搜索结果

9、h\c切换(针对C、C++)

下载插件:a.vim 地址http://www.vim.org/scripts/download_script.php?src_id=7218

将a.vim复制到d:\Program Files\Vim\vim73\plugin,在_vimrc中添加: 
nnoremap <silent> <F12> :A<CR> 
用gvim打开源码文件后,按F12即可以在c/h文件中切换,也可以通过输入:A实现。

10、高亮书签

下载插件:visualmark.vim 地址http://www.vim.org/scripts/download_script.php?src_id=4700

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

使用F2在书签之间正向切换,shift+F2反向切换。

11、Python代码补全

下载插件pydiction-1.2.zip

解压后,将里面的python_pydiction.vim文件复制到D:\Program Files\Vim\vimfiles\ftplugin

将complete-dict 和 pydiction.py复制到D:\Program Files\Vim\vimfiles\ftplugin\pydiction

在_vimrc文件中增加配置如下:

filetype plugin on  “启用filetype插件

let g:pydiction_location = 'D:\Program Files\Vim\vimfiles\ftplugin\pydiction\complete-dict' 
let g:pydiction_menu_height = 20 ”设置弹出菜单的高度,默认是15

用gvim打开一个py文件,输入row+[tab],就可以看到自动补全的代码选项了

12、python编译

下载VimPdb,解压后拷贝VimPdb.py,VimPdb.vim到plugin即可。

用vim代开python代码文件,按F5运行,然后按F2设置断点,在运行到断点后可以用按F12可以查看Stack Trace,F3查看变量和参数值。

不过这种方法使用了一下,经常会死掉,不知道为什么,所以在网上找到了另外一种方法:

在_vimrc增加

python << EOF
import time
import vim
def SetBreakpoint():
nLine = int( vim.eval( 'line(".")'))
strLine = vim.current.line
i = 0
strWhite = ""
while strLine[i] == ' ' or strLine[i] == "\t":
i += 1
strWhite += strLine[i]
vim.current.buffer.append(
"%(space)spdb.set_trace() %(mark)s Breakpoint %(mark)s" %
{'space':strWhite, 'mark': '#' * 30}, nLine - 1)
for strLine in vim.current.buffer:
if strLine == "import pdb":
break
else:
vim.current.buffer.append( 'import pdb', 0)
vim.command( 'normal j1')
break
vim.command( 'map <C-M> :py SetBreakpoint()<cr>') def RemoveBreakpoints():
nCurrentLine = int( vim.eval( 'line(".")'))
nLines = []
nLine = 1
for strLine in vim.current.buffer:
if strLine == 'import pdb' or strLine.lstrip()[:15] == 'pdb.set_trace()':
nLines.append( nLine)
nLine += 1
nLines.reverse()
for nLine in nLines:
vim.command( 'normal %dG' % nLine)
vim.command( 'normal dd')
if nLine < nCurrentLine:
nCurrentLine -= 1
vim.command( 'normal %dG' % nCurrentLine)
vim.command( 'map <C-U> :py RemoveBreakpoints()<cr>')
vim.command( 'map <C-D> :!python %<cr>')
EOF

然后在要调试的代码里面用ctrl-M设断点 
ctrl-D运行

13、Python代码检查

下载pyflakes,解压缩后把pyflakes.vim文件和pyflakes目录拷贝套ftplugin\python目录中打开一个有问题的python源代码文件,执行命令:cc,即可进行代码检查:

【转】Gvim开发环境配置笔记--Windows篇的更多相关文章

  1. Env:Gvim开发环境配置笔记--Windows篇

    转自:http://www.cnblogs.com/xiekeli/archive/2012/08/13/2637176.html 加班的时候,听同事提到gvim在windows下的使用,然后突然想起 ...

  2. Java 开发环境配置(Windows篇)

    window系统安装java 下载JDK 首先我们需要下载java开发工具包JDK,下载地址:http://www.oracle.com/technetwork/java/javase/downloa ...

  3. Ubuntu虚拟机+ROS+Android开发环境配置笔记

    Ubuntu虚拟机+ROS+Android开发环境配置笔记 虚拟机设置: 1.本地环境:Windows 7:VMWare:联网 2.虚拟环境 :Ubuntu 14.04. 比較稳定,且支持非常多ROS ...

  4. Node.js与VUE安装及环境配置之Windows篇

    Node.js安装及环境配置之Windows篇 https://www.cnblogs.com/zhouyu2017/p/6485265.html Node.js安装及环境配置之Windows篇htt ...

  5. Node.js安装及环境配置之Windows篇

    Node.js安装及环境配置之Windows篇   一.安装环境 1.本机系统:Windows 10 Pro(64位)2.Node.js:v6.9.2LTS(64位) 二.安装Node.js步骤 1. ...

  6. Node.js安装及环境配置之Windows篇(转:https://www.cnblogs.com/zhouyu2017/p/6485265.html)

    Node.js安装及环境配置之Windows篇(原文地址:https://www.cnblogs.com/zhouyu2017/p/6485265.html)   一.安装环境 1.本机系统:Wind ...

  7. Mac电脑配置IOS React Native开发环境配置笔记

    React Native(以下简称RN)的开发环境配置直接参考官方文档即可完成,不过对小白来说东西有点多,有些名词不是很好理解,这里就官方的安装文档稍微展开说一下. 中文版配置说明:不错的中文说明.官 ...

  8. 安卓开发环境配置之Windows+ADT+eclipse

    安卓环境搭建之Windows+ADT+eclipse 要点: 1.安装JDK 2.安装Android SDK 3.安装eclipse 4.安装ADT 5.安装调试环境 正文: 1.安装JDK 1.1准 ...

  9. python开发环境配置(Windows)

    简介 由于在搭建pyhon开发环境时会出现各种各样的问题,因此将这些问题记录下来 1.下载python 从官网下载对应系统的python版本(最新稳定版即可):官网地址为:python下载地址, 建议 ...

随机推荐

  1. Uva 839 Not so Mobile

    0.最后输出的yes no的大小写 1.注意 递归边界   一直到没有左右子树 即b1=b2=false的时候 才返回 是否 天平平衡. 2.注意重量是利用引用来传递的 #include <io ...

  2. CSS3设置多张背景图片

    background-image:url("1.jpg"),url("2.jpg"),url("3.jpg");background-rep ...

  3. 利用StringList对象来管理这些动态生成的对象

    如果程序需要动态创建大量的对象,那么我们可以利用StringList对象来管理这些动态生成的对象.1.创建StringList对象:OBJ := TStringList.Create; 2.保存动态生 ...

  4. eclipse下Android无法自动生成apk文件怎么办?

    eclipse下Android无法自动生成apk文件怎么办? 现象:创建android工程后,通过手动build/clean或自动build均无法在bin文件夹下生成.apk文件 解决方法:进入win ...

  5. BZOJ4426 : [Nwerc2015]Better Productivity最大生产率

    如果一个区间包含另一个区间,那么这两个区间是否在一起的生产率是一样的. 将所有这种包含了其他区间的区间放入数组$b$,其余的放入数组$c$,有多个相同的时候则从$b$移一个到$c$. 那么$c$里所有 ...

  6. BZOJ3421 : Poi2013 Walk

    最多只有一个连通块大小大于$nk$,所以用hash表进行BFS的时候只扩展$nk$步即可. 时间复杂度$O(n^2k)$. #include<cstdio> typedef long lo ...

  7. BZOJ2149 : 拆迁队

    设$c[i]=g[i]+\frac{i(i+1)}{2}-a[i]\times i-a[i]$,$d[i]=a[i]-i$ $f[i]$表示以$i$为结尾最多保留多少个建筑,则 $f[i]=\max( ...

  8. [R]R语言里的异常处理与错误控制

    之前一直只是在写小程序脚本工具,几乎不会对异常和错误进行控制和处理. 随着脚本结构和逻辑更复杂,脚本输出结果的准确性验证困难,同时已发布脚本的维护也变得困难.所以也开始考虑引入异常处理和测试工具的事情 ...

  9. sqlite 数据类型 全面

    http://blog.csdn.net/jin868/article/details/5961263 一般数据采用的固定的静态数据类型,而SQLite采用的是动态数据类型,会根据存入值自动判断.SQ ...

  10. [题解+总结]NOIP动态规划大合集

    1.前言 NOIP2003-2014动态规划题目大合集,有简单的也有难的(对于我这种动态规划盲当然存在难的),今天就把这些东西归纳一下,做一个比较全面的总结,方便对动态规划有一个更深的理解. 2.NO ...