我的vim/gvim配置.vimrc

前端之家收集整理的这篇文章主要介绍了我的vim/gvim配置.vimrc前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文永久地址:https://my.oschina.net/bysu/blog/1547768

1.下载:

ftp://ftp.vim.org/pub/vim/pc/vim80-586rt.zip

ftp://ftp.vim.org/pub/vim/pc/gvim80-586.zip

2.把两个压缩文件里面的内容都解压,放到一起(vim),目录结构如下图

3.把目录中的vimrc_example.vim文件重命名为_vimrc,并把下面的配置覆盖进去即可

  1. " An example for a vimrc file.
  2. "
  3. " Maintainer: Bram Moolenaar <Bram@vim.org>
  4. " Last change: 2016 Jul 28
  5. "
  6. " To use it,copy it to
  7. " for Unix and OS/2: ~/.vimrc
  8. " for Amiga: s:.vimrc
  9. " for MS-DOS and Win32: $VIM\_vimrc
  10. " for OpenVMS: sys$login:.vimrc
  11.  
  12. " When started as "evim",evim.vim will already have done these settings.
  13. if v:progname =~? "evim"
  14. finish
  15. endif
  16.  
  17. " Get the defaults that most users want.
  18. source $VIMRUNTIME/defaults.vim
  19.  
  20. if has("vms")
  21. set nobackup " do not keep a backup file,use versions instead
  22. else
  23. set backup " keep a backup file (restore to prevIoUs version)
  24. if has('persistent_undo')
  25. set undofile " keep an undo file (undo changes after closing)
  26. endif
  27. endif
  28.  
  29. if &t_Co > 2 || has("gui_running")
  30. " Switch on highlighting the last used search pattern.
  31. set hlsearch
  32. endif
  33.  
  34. " Only do this part when compiled with support for autocommands.
  35. if has("autocmd")
  36.  
  37. " Put these in an autocmd group,so that we can delete them easily.
  38. augroup vimrcEx
  39. au!
  40.  
  41. " For all text files set 'textwidth' to 78 characters.
  42. autocmd FileType text setlocal textwidth=78
  43.  
  44. augroup END
  45.  
  46. else
  47.  
  48. set autoindent " always set autoindenting on
  49.  
  50. endif " has("autocmd")
  51.  
  52. " Add optional packages.
  53. "
  54. " The matchit plugin makes the % command work better,but it is not backwards
  55. " compatible.
  56. if has('Syntax') && has('eval')
  57. packadd matchit
  58. endif
  59.  
  60. "==============================去掉启动提示文案:帮助乌干达儿童之类的提示
  61. set shortmess=atI
  62.  
  63. "===============================设置主题
  64. colorscheme darkblue
  65.  
  66. "===============================设置字体大小
  67. set guifont=Consolas:h12 "h12字体大小,bh12中的b表示黑体
  68. "set guifontwide=Microsoft/ YaHei:h12
  69.  
  70. "=================开启语法高亮提示
  71. Syntax on
  72.  
  73. "==============缩进
  74. set cin nu ts=4 sw=4 sts=4 et acd noswapfile nobackup
  75. set bs=eol,start,indent
  76.  
  77. "==================隐藏菜单、工具、滚动条============================
  78. ":set guioptions-=m "remove menu bar
  79. ":set guioptions-=T "remove toolbar
  80. ":set guioptions-=r "remove right-hand scroll bar
  81. ":set guioptions-=L "remove left-hand scroll bar
  82. if has("gui_running")
  83. au GUIEnter * simalt ~x " 窗口启动时自动最大化
  84. set guioptions-=m " 隐藏菜单
  85. set guioptions-=T " 隐藏工具栏
  86. "set guioptions-=L " 隐藏左侧滚动条
  87. set guioptions-=r " 隐藏右侧滚动条
  88. set guioptions-=b " 隐藏底部滚动条
  89. set showtabline=0 " 隐藏Tab栏
  90. endif
  91.  
  92. "==========================中文显示乱码
  93. set encoding=utf-8
  94. set fileencodings=utf-8,chinese,latin-1
  95. if has("win32")
  96. set fileencoding=chinese
  97. else
  98. set fileencoding=utf-8
  99. endif
  100. "解决菜单乱码
  101. source $VIMRUNTIME/delmenu.vim
  102. source $VIMRUNTIME/menu.vim
  103. "解决consle输出乱码
  104. language messages zh_CN.utf-8
  105.  
  106. "================================符号自动补全
  107. inoremap ' ''<ESC>i
  108. inoremap " ""<ESC>i
  109. inoremap ( ()<ESC>i
  110. inoremap [ []<ESC>i
  111. inoremap < <><ESC>i
  112. inoremap { {<CR>}<ESC>O
  113. inoremap ) <c-r>=ClosePair(')')<CR>
  114. inoremap > <c-r>=ClosePair('>')<CR>
  115. inoremap } <c-r>=ClosePair('}')<CR>
  116. inoremap ] <c-r>=ClosePair(']')<CR>
  117.  
  118. function! ClosePair(char)
  119. if getline('.')[col('.') - 1] == a:char
  120. return "\<Right>"
  121. else
  122. return a:char
  123. endif
  124. endf
  125.  
  126. "=================================设置跳出自动补全的括号
  127. func SkipPair()
  128. let str = getline('.')[col('.')-1]
  129. if str == ')' || str == ']' || str == '"' || str == "'" || str == '}'
  130. return "\<Right>"
  131. elseif strpart(getline('.'),col('.')-1)=~'^\s*$'
  132. return "\<Tab>"
  133. else
  134. return "\<C-N>"
  135. endif
  136. endfunc
  137. " tab键绑定为跳出括号
  138. inoremap <TAB> <c-r>=SkipPair()<CR>
  139.  
  140. "=====================小写转换大写
  141. inoremap <C-u> <esc>gUiwea
  142.  
  143. "=====================插入模式移动光标
  144. inoremap <M-k> <Up>
  145. inoremap <M-j> <Down>
  146. inoremap <M-h> <Left>
  147. inoremap <M-l> <Right>
  148. inoremap <M-a> <Home>
  149. inoremap <M-e> <End>
  150.  
  151. " Rubout word / line and enter insert mode
  152. " use <Esc><Right> instead of <C-o>
  153. inoremap <C-w> <Esc>dbcl
  154. " delete
  155. inoremap <C-u> <Esc>d0cl
  156. inoremap <C-k> <Esc><Right>C
  157. inoremap <C-d> <Esc><Right>s
  158. inoremap <C-d> <C-o>de
  159. inoremap <M-d> <C-o>de
  160.  
  161. "===================编译javacc++、python以及sh脚本
  162. "=======================按F5进行编译运行windows,Linux下需在运行的命令里面加当前目录./
  163. map <F5> :call CompileRunGcc()<CR>
  164. imap <F5> <ESC>:call CompileRunGcc()<CR>
  165. func! CompileRunGcc()
  166. exec "w"
  167. exec "cd %:p:h"
  168. if &filetype == 'c'
  169. exec "!g++ % -o %<"
  170. exec "! %<"
  171. elseif &filetype == 'cpp'
  172. exec "!g++ -std=c++11 -O2 % -o %<"
  173. exec "! %<"
  174. elseif &filetype == 'java'
  175. exec "!javac %<"
  176. exec "!java %<"
  177. elseif &filetype == 'py'
  178. exec "!python %<"
  179. elseif &filetype == 'sh'
  180. :!./%
  181. endif
  182. endfunc
  183.  
  184. "======================<F9>gdb调试cc++
  185. map <F9> :call Debug()<CR>
  186. imap <F9> :call Debug()<CR>
  187. func! Debug()
  188. exec "w"
  189. exec "cd %:p:h"
  190. if &filetype == 'c'
  191. exec "!gcc % -g -o %< -gstabs+"
  192. exec "!gdb %<"
  193. elseif &filetype == 'cpp'
  194. exec "!g++ % -g -o %< -gstabs+"
  195. exec "!gdb %<"
  196. endfunc
  197.  
  198.  
  199. "=====================AIT+/进行注释
  200. inoremap <M-/> <Home>//
  201. nmap <M-/> <Home>i//<ESC>
  202.  
  203. "=====================复制粘贴
  204. map <C-A> ggVG " 映射全选 ctrl+a
  205. map! <C-A> <Esc>ggVGY
  206. map <C-c> "+y " 映射复制到系统剪切板
  207. map! <C-c> "+y " 映射复制到系统剪切板
  208. nmap <C-v> "+gp " 映射粘贴
  209. imap <C-v> <Esc>"+gp

4.在环境变量path里面加入vim目录的绝对路径,譬如我的

  1. D:\bysu\Application\vim\

注意:如果path里面还有其他路径,且vim是放在最后面,需要输入分号;然后加上你的路径。如:

  1. ;D:\bysu\Application\vim\

5.打开运行(Ctrl+r),输入gvim,回车即可打开gvim编辑器(可以把vim目录的中gvim.exe重命名为vi.exe,然后输入vi,回车即可打开gvim编辑器)

linux的vim配置文件

  1. " All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
  2. " the call to :runtime you can find below. If you wish to change any of those
  3. " settings,you should do it in this file (/etc/vim/vimrc),since debian.vim
  4. " will be overwritten everytime an upgrade of the vim packages is performed.
  5. " It is recommended to make changes after sourcing debian.vim since it alters
  6. " the value of the 'compatible' option.
  7.  
  8. " This line should not be removed as it ensures that varIoUs options are
  9. " properly set to work with the Vim-related packages available in Debian.
  10. runtime! debian.vim
  11.  
  12. " Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.
  13. " This happens after /etc/vim/vimrc(.local) are loaded,so it will override
  14. " any settings in these files.
  15. " If you don't want that to happen,uncomment the below line to prevent
  16. " defaults.vim from being loaded.
  17. " let g:skip_defaults_vim = 1
  18.  
  19. " Uncomment the next line to make Vim more Vi-compatible
  20. " NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
  21. " options,so any other options should be set AFTER setting 'compatible'.
  22. "set compatible
  23.  
  24. " Vim5 and later versions support Syntax highlighting. Uncommenting the next
  25. " line enables Syntax highlighting by default.
  26. Syntax on
  27.  
  28. " If using a dark background within the editing area and Syntax highlighting
  29. " turn on this option as well
  30. "set background=dark
  31.  
  32. " Uncomment the following to have Vim jump to the last position when
  33. " reopening a file
  34. "if has("autocmd")
  35. " au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
  36. "endif
  37.  
  38. " Uncomment the following to have Vim load indentation rules and plugins
  39. " according to the detected filetype.
  40. "if has("autocmd")
  41. " filetype plugin indent on
  42. "endif
  43.  
  44. " The following are commented out as they cause vim to behave a lot
  45. " differently from regular Vi. They are highly recommended though.
  46. "set showcmd " Show (partial) command in status line.
  47. "set showmatch " Show matching brackets.
  48. "set ignorecase " Do case insensitive matching
  49. "set smartcase " Do smart case matching
  50. "set incsearch " Incremental search
  51. "set autowrite " Automatically save before commands like :next and :make
  52. "set hidden " Hide buffers when they are abandoned
  53. "set mouse=a " Enable mouse usage (all modes)
  54.  
  55. " Source a global configuration file if available
  56. if filereadable("/etc/vim/vimrc.local")
  57. source /etc/vim/vimrc.local
  58. endif
  59. set shortmess=atI
  60.  
  61. "===============================设置主题
  62. colorscheme darkblue
  63.  
  64. ""===============================设置字体大小
  65. set guifont=Consolas:h12 "h12字体大小,bh12中的b表示黑体
  66. "set guifontwide=Microsoft/ YaHei:h12
  67.  
  68. ""=================开启语法高亮提示
  69. Syntax on
  70.  
  71. "==============缩进
  72. set cin nu ts=4 sw=4 sts=4 et acd noswapfile nobackup
  73. set bs=eol,indent
  74.  
  75. "==================隐藏菜单、工具、滚动条============================
  76. "set guioptions-=m "remove menu bar
  77. "set guioptions-=T "remove toolbar
  78. "set guioptions-=r "remove right-hand scroll bar
  79. ":set guioptions-=L "remove left-hand scroll bar
  80. if has("gui_running")
  81. au GUIEnter * simalt ~x " 窗口启动时自动最大化
  82. set guioptions-=m " 隐藏菜单
  83. set guioptions-=T " 隐藏工具栏
  84. "set guioptions-=L " 隐藏左侧滚动条
  85. "set guioptions-=r " 隐藏右侧滚动条
  86. "set guioptions-=b " 隐藏底部滚动条
  87. "set showtabline=0 " 隐藏Tab
  88. endif
  89. "
  90. ""==========================中文显示乱码
  91. set encoding=utf-8
  92. set fileencodings=utf-8,latin-1
  93. if has("win32")
  94. set fileencoding=chinese
  95. else
  96. set fileencoding=utf-8
  97. endif
  98. "解决菜单乱码
  99. "source $VIMRUNTIME/delmenu.vim
  100. "source $VIMRUNTIME/menu.vim
  101. ""解决consle输出乱码
  102. language messages zh_CN.utf-8
  103.  
  104. "================================符号自动补全
  105. ""inoremap ' ''<ESC>i
  106. ""inoremap " ""<ESC>i
  107. ""inoremap ( ()<ESC>i
  108. ""inoremap [ []<ESC>i
  109. ""inoremap < <><ESC>i
  110. ""inoremap { {<CR>}<ESC>O
  111. inoremap ( ()<ESC>i
  112. inoremap ) <c-r>=ClosePair(')')<CR>
  113. inoremap { {}<ESC>i
  114. inoremap } <c-r>=ClosePair('}')<CR>
  115. inoremap [ []<ESC>i
  116. inoremap ] <c-r>=ClosePair(']')<CR>
  117. inoremap < <><ESC>i
  118. inoremap > <c-r>=ClosePair('>')<CR>
  119. inoremap " ""<ESC>i
  120. inoremap ' ''<ESC>i
  121.  
  122. function! ClosePair(char)
  123. if getline('.')[col('.') - 1] == a:char
  124. return "\<Right>"
  125. else
  126. return a:char
  127. endif
  128. endf
  129.  
  130. "=================================设置跳出自动补全的括号
  131. func SkipPair()
  132. let str = getline('.')[col('.')-1]'')]'')
  133. if str == ')' || str == ']' || str == '"' || str == "'" || str == '}'
  134. return "\<Right>"
  135. elseif strpart(getline('.'),col('.')-1)=~'^\s*$'
  136. return "\<Tab>"
  137. else
  138. return "\<C-N>"
  139. endif
  140. endfunc
  141.  
  142. " 将tab键绑定为跳出括号
  143. inoremap <TAB> <c-r>=SkipPair()<CR>
  144.  
  145. "=====================小写转换大写
  146. inoremap <C-u> <esc>gUiwea
  147.  
  148. ""=====================插入模式移动光标
  149. inoremap <C-k> <Up>
  150. inoremap <C-j> <Down>
  151. inoremap <C-h> <Left>
  152. inoremap <C-l> <Right>
  153. inoremap <C-a> <Home>
  154. inoremap <C-e> <End>
  155. "Rubout word / line and enter insert mode
  156. " use <Esc><Right> instead of <C-o>
  157. inoremap <C-w> <Esc>dbcl
  158. " delete
  159. inoremap <C-u> <Esc>d0cl
  160. inoremap <M-k> <Esc><Right>C
  161. inoremap <C-d> <Esc><Right>s
  162. inoremap <C-d> <C-o>de
  163. inoremap <M-d> <C-o>de
  164.  
  165. "===================编译javacc++、python以及sh脚本
  166. ""=======================按F5进行编译运行windowsLinux下需在运行的命令里面加当前目录./
  167. map <F5> :call CompileRunGcc()<CR>
  168. imap <F5> <ESC>:call CompileRunGcc()<CR>
  169. func! CompileRunGcc()
  170. exec "w"
  171. exec "cd %:p:h"
  172. if &filetype == 'c'
  173. exec "!g++ % -o %<"
  174. exec "! ./%<"
  175. elseif &filetype == 'cpp'
  176. exec "!g++ -std=c++11 -O2 % -o %<"
  177. exec "! ./%<"
  178. elseif &filetype == 'java'
  179. exec "!javac %"
  180. exec "!java %<"
  181. elseif &filetype == 'py'
  182. exec "!python %<"
  183. elseif &filetype == 'sh'
  184. :!./%
  185. endif
  186. endfunc
  187.  
  188. "======================<F9>gdb调试c或c++
  189. map <F9> :call Debug()<CR>
  190. imap <F9> :call Debug()<CR>
  191. func! Debug()
  192. exec "w"
  193. exec "cd %:p:h"
  194. if &filetype == 'c'
  195. exec "!gcc % -g -o %< -gstabs+"
  196. exec "!gdb ./%<"
  197. elseif &filetype == 'cpp'
  198. exec "!g++ % -g -o %< -gstabs+"
  199. exec "!gdb ./%<"
  200. endfunc
  201.  
  202. "=====================复制粘贴
  203. map <C-A> ggVG " 映射全选 ctrl+a
  204. map! <C-A> <Esc>ggVGY
  205. map <C-c> "+y " 映射复制到系统剪切板
  206. map! <C-c> "+y " 映射复制到系统剪切板
  207. "nmap <C-v> "+gp " 映射粘贴
  208. "imap <C-v> <Esc>"+gp

参考:

http://vim.wikia.com/wiki/Hide_toolbar_or_menus_to_see_more_text

https://blog.alswl.com/2012/04/vim-emacs-key-binding/

http://blog.csdn.net/lalor/article/details/7437258

http://www.pythonclub.org/vim/map-basic

https://segmentfault.com/q/1010000004870420

https://www.w3cschool.cn/vim/drcj1pu5.html

猜你在找的Bash相关文章