[关闭]
@bergus 2017-02-15T16:15:26.000000Z 字数 7032 阅读 1611

我的vim配置

vim


  1. set nocompatible " be iMproved
  2. filetype off " required!
  3. " set the runtime path to include Vundle and initialize
  4. set rtp+=~/.vim/bundle/Vundle.vim
  5. " alternatively, pass a path where Vundle should install plugins
  6. " call vundle#begin('~/some/path/here')
  7. call vundle#begin()
  8. " let Vundle manage Vundle, required
  9. Plugin 'gmarik/Vundle.vim'
  10. Plugin 'Shougo/neocomplete.vim'
  11. Plugin 'majutsushi/tagbar.git'
  12. Plugin 'scrooloose/nerdtree.git'
  13. Plugin 'wincent/command-t'
  14. Plugin 'vim-airline/vim-airline'
  15. Plugin 'vim-airline/vim-airline-themes'
  16. Plugin 'nvie/vim-flake8'
  17. Plugin 'bash-support.vim'
  18. Bundle 'rking/ag.vim'
  19. Bundle 'scrooloose/syntastic'
  20. " thrift
  21. " Plugin 'solarnz/thrift.vim'
  22. " golang 插件
  23. " Plugin 'fatih/vim-go'
  24. "nim插件
  25. Bundle 'zah/nim.vim'
  26. "set runtimepath^=~/.vim/bundle/ag
  27. " required
  28. call vundle#end()
  29. """"""""""""""""""""""""""""""""""""""""""
  30. " Jump to tag
  31. fun! JumpToDef()
  32. if exists("*GotoDefinition_" . &filetype)
  33. call GotoDefinition_{&filetype}()
  34. else
  35. exe "norm! \<C-]>"
  36. endif
  37. endf
  38. nn <M-g> :call JumpToDef()<cr>
  39. ino <M-g> <esc>:call JumpToDef()<cr>i
  40. """"""""""""""""""""""""""""""""""""""""""
  41. " 代码自动提醒
  42. set tags=/usr/local/bin/ctags
  43. " required
  44. filetype plugin indent on
  45. " To ignore plugin indent changes, instead use:
  46. "filetype plugin on
  47. "
  48. " Brief help
  49. " :PluginList - lists configured plugins
  50. " :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
  51. " :PluginSearch foo - searches for foo; append `!` to refresh local cache
  52. " :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
  53. "
  54. " see :h vundle for more details or wiki for FAQ
  55. " Put your non-Plugin stuff after this line
  56. "
  57. " 代码高亮用的
  58. let g:go_disable_autoinstall = 0
  59. let g:go_highlight_functions = 1
  60. let g:go_highlight_methods = 1
  61. let g:go_highlight_structs = 1
  62. let g:go_highlight_operators = 1
  63. let g:go_highlight_build_constraints = 1
  64. let g:go_fmt_command = "goimports" "保存的时候自动运行goimports
  65. " 自动补全自动启动
  66. let g:neocomplete#enable_at_startup = 1
  67. " 颜色配置
  68. colorscheme molokai
  69. " 标签分析
  70. let g:tagbar_type_go = {
  71. \ 'ctagstype' : 'go',
  72. \ 'kinds' : [
  73. \ 'p:package',
  74. \ 'i:imports:1',
  75. \ 'c:constants',
  76. \ 'v:variables',
  77. \ 't:types',
  78. \ 'n:interfaces',
  79. \ 'w:fields',
  80. \ 'e:embedded',
  81. \ 'm:methods',
  82. \ 'r:constructor',
  83. \ 'f:functions'
  84. \ ],
  85. \ 'sro' : '.',
  86. \ 'kind2scope' : {
  87. \ 't' : 'ctype',
  88. \ 'n' : 'ntype'
  89. \ },
  90. \ 'scope2kind' : {
  91. \ 'ctype' : 't',
  92. \ 'ntype' : 'n'
  93. \ },
  94. \ 'ctagsbin' : 'gotags',
  95. \ 'ctagsargs' : '-sort -silent'
  96. \ }
  97. " 标签映射
  98. execute "set <M-i>=\ei"
  99. execute "set <M-o>=\eo"
  100. execute "set <M-p>=\ep"
  101. execute "set <M-u>=\eu"
  102. execute "set <M-l>=\el"
  103. execute "set <M-n>=\en"
  104. execute "set <M-y>=\ey"
  105. execute "set <M-c>=\ec"
  106. nmap <M-p> :TagbarToggle<CR>
  107. imap <M-p> <esc>:TagbarToggle<CR>i
  108. nmap <M-u> :NERDTreeToggle<CR>
  109. imap <M-u> <esc>:NERDTreeToggle<CR>
  110. nmap <C-c> :q<CR>
  111. nmap <M-o> :tabn<CR>
  112. imap <M-o> <esc>:tabn<CR>
  113. nmap <M-i> :tabp<CR>
  114. imap <M-i> <esc>:tabp<CR>
  115. nmap <M-l> :w<CR>:GoLint<CR>
  116. nmap <M-n> :GoDef<CR>
  117. nmap <C-z> :undo<CR>
  118. nmap <M-y> :GoErrCheck<CR>
  119. nmap <C-s> :w<CR>:GoMetaLinter<CR>
  120. imap <C-s> <esc>:w<CR>:GoMetaLinter<CR>
  121. imap <M-c> <esc>:pc<CR>
  122. nmap <M-c> :pc<CR>
  123. set backspace=indent,eol,start " 让backspace能正常工作的配置
  124. " 这是对PowerLine的设置
  125. set encoding=utf-8
  126. set laststatus=2
  127. let g:Powerline_symbols='unicode'
  128. " tab设置
  129. set ts=4
  130. set expandtab
  131. " 解决esc延迟问题
  132. set timeoutlen=1000 ttimeoutlen=0
  133. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  134. ""实用设置
  135. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  136. "设置当文件被改动时自动载入
  137. set autoread
  138. "自动切换当前目录为当前文件所在的目录
  139. set autochdir
  140. "选中一段文字并全文搜索这段文字
  141. vmap <silent> ,/ y/<C-R>=escape(@", '\\/.*$^~[]')<CR><CR>
  142. vmap <silent> ,? y?<C-R>=escape(@", '\\/.*$^~[]')<CR><CR>
  143. "quickfix模式
  144. autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>
  145. "代码补全
  146. set completeopt=preview,menu
  147. "允许插件
  148. filetype plugin on
  149. "共享剪贴板
  150. set clipboard+=unnamed
  151. "从不备份
  152. set nobackup
  153. "make 运行
  154. :set makeprg=g++\ -Wall\ \ %
  155. "自动保存
  156. set autowrite
  157. set ruler " 打开状态栏标尺
  158. set cursorline " 突出显示当前行
  159. set magic " 设置魔术
  160. set guioptions-=T " 隐藏工具栏
  161. set guioptions-=m " 隐藏菜单栏
  162. set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\%{&encoding}\ %c:%l/%L%)\
  163. " 设置在状态行显示的信息
  164. set foldcolumn=0
  165. set foldmethod=indent
  166. set foldlevel=3
  167. " 开始折叠
  168. set foldenable
  169. " 不要使用vi的键盘模式,而是vim自己的
  170. set nocompatible
  171. " 语法高亮
  172. syntax enable
  173. " 去掉输入错误的提示声音
  174. "解决菜单乱码
  175. set encoding=utf-8
  176. "fileencodings需要注意顺序,前面的字符集应该比后面的字符集大
  177. set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
  178. set imcmdline
  179. set noeb
  180. " 在处理未保存或只读文件的时候,弹出确认
  181. set confirm
  182. " 自动缩进
  183. set autoindent
  184. set cindent
  185. " Tab键的宽度
  186. set tabstop=4
  187. " 统一缩进为4
  188. set softtabstop=4
  189. set shiftwidth=4
  190. " 不要用空格代替制表符
  191. set noexpandtab
  192. " 在行和段开始处使用制表符
  193. set smarttab
  194. " 显示行号
  195. set number
  196. " 历史记录数
  197. set history=1000
  198. "禁止生成临时文件
  199. set nobackup
  200. set noswapfile
  201. " 搜索忽略大小写
  202. set ignorecase
  203. " 搜索逐字符高亮
  204. set hlsearch
  205. set incsearch
  206. " 行内替换
  207. set gdefault
  208. " 编码设置
  209. set enc=utf-8
  210. set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
  211. " 语言设置
  212. set langmenu=zh_CN.UTF-8
  213. set helplang=cn
  214. " 不自动换行
  215. set nowrap
  216. " 设置超过100字符自动换行
  217. set textwidth=100
  218. " 设置超过100列的字符带下划线
  219. au BufWinEnter * let w:m2=matchadd('Underlined', '\%>80v.\+', -1)
  220. syn match out80 /\%80v./ containedin=ALL
  221. hi out80 guifg=white guibg=red ctermfg=white ctermbg=red
  222. " 我的状态行显示的内容(包括文件类型和解码)
  223. " set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
  224. " 总是显示状态行
  225. set laststatus=2
  226. " 命令行(在状态行下)的高度,默认为1,这里是2
  227. set cmdheight=2
  228. " 侦测文件类型
  229. filetype on
  230. " 载入文件类型插件
  231. filetype plugin on
  232. " 为特定文件类型载入相关缩进文件
  233. filetype indent on
  234. " 保存全局变量
  235. set viminfo+=!
  236. " 带有如下符号的单词不要被换行分割
  237. set iskeyword+=_,$,@,%,#,-
  238. " 字符间插入的像素行数目
  239. set linespace=0
  240. " 增强模式中的命令行自动完成操作
  241. set wildmenu
  242. " 使回格键(backspace)正常处理indent, eol, start
  243. set backspace=2
  244. " 允许backspace和光标键跨越行边界
  245. set whichwrap+=<,>,h,l
  246. " 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
  247. set mouse=a
  248. set selection=exclusive
  249. set selectmode=mouse,key
  250. " 通过使用: commands命令,告诉我们文件的哪一行被改变过
  251. set report=0
  252. " 在被分割的窗口间显示空白,便于阅读
  253. set fillchars=vert:\ ,stl:\ ,stlnc:\
  254. " 高亮显示匹配的括号
  255. set showmatch
  256. " 匹配括号高亮的时间(单位是十分之一秒)
  257. set matchtime=1
  258. " 光标移动到buffer的顶部和底部时保持3行距离
  259. set scrolloff=3
  260. " C程序提供自动缩进
  261. set smartindent
  262. " 高亮显示普通txt文件(需要txt.vim脚本)
  263. au BufRead,BufNewFile * setfiletype txt
  264. "启动后最大化
  265. au GUIEnter * simalt ~x
  266. " 置粘贴模式,这样粘贴过来的程序代码就不会错位了。
  267. "set paste
  268. "设置字体
  269. if has("gui")
  270. if has("win32")
  271. "启动时会弹出字体选择框,如果取消,则采用系统默认字体
  272. set guifont=*
  273. "Windows默认使用的字体,字体较粗
  274. "set guifont=Fixedsys
  275. "中文显示变形,字体较粗
  276. "set guifont=Monospace:h9
  277. "中文显示变形,字体较细
  278. "set guifont=Consolas:h9
  279. "中文显示变形,字体较细
  280. "set guifont=Lucida\ Console:h9
  281. "中文显示变形,字体较细
  282. set guifont=Monaco:h9
  283. "中文显示变形,字体较细
  284. "set guifont=Andale\ Mono:h10
  285. "中文显示变形,字体较细
  286. "set guifont=Bitstream\ Vera\ Sans\ Mono:h9
  287. "需要运行修改版的gvim才能识别
  288. "set guifont=YaHei\ Consolas\ Hybrid:h9
  289. "如果guifontwide采用中文字体,汉字将自动使用guifontwide,英文自动使用guifont
  290. set guifontwide=YaHei\ Consolas\ Hybrid:h9
  291. else
  292. set guifont=SimSun:h10
  293. endif
  294. "set columns=128 lines=36
  295. endif
  296. " 打开链接
  297. function! OpenUrl()
  298. let s:url = GetPatternAtCursor('\v(https?://|ftp://|file:/{3}|www\.)((\w|-)+\.)+(\w|-)+(:\d+)?(/(\w|[~@#$%^&+=/.?-])+)?')
  299. "echo s:url
  300. if s:url == ""
  301. echohl WarningMsg
  302. echomsg '在光标处未发现URL!'
  303. echohl None
  304. else
  305. if GetSystem() == "windows"
  306. call system("explorer " . s:url)
  307. else
  308. call system("firefox " . s:url . " &")
  309. endif
  310. endif
  311. unlet s:url
  312. endfunction
  313. nmap <C-LeftMouse> :call OpenUrl()<CR>
  314. set wildignore+=versions/*,cache/*
  315. "开启光亮光标行
  316. set cursorline
  317. hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
  318. "开启高亮光标列
  319. set cursorcolumn
  320. hi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
  321. let g:airline_theme="luna"
  322. "这个是安装字体后 必须设置此项"
  323. let g:airline_powerline_fonts = 1
  324. "打开tabline功能,方便查看Buffer和切换,这个功能比较不错"
  325. "我还省去了minibufexpl插件,因为我习惯在1Tab下用多个buffer"
  326. let g:airline#extensions#tabline#enabled = 1
  327. let g:airline#extensions#tabline#buffer_nr_show = 1
  328. "设置切换Buffer快捷键"
  329. nnoremap <C-N> :bn<CR>
  330. nnoremap <C-P> :bp<CR>
  331. " 关闭状态显示空白符号计数,这个对我用处不大"
  332. let g:airline#extensions#whitespace#enabled = 0
  333. let g:airline#extensions#whitespace#symbol = '!'
  334. set autochdir
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注