Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
garland's vimrc
""""""""""""
"基础设置
""""""""""""
syntax on "开启语法高亮
"filetype on "检测文件类型
filetype indent on "根据不同文件类型采用不同缩进
filetype plugin on "允许插件
filetype plugin indent on "启用自动补全
set autoread "文件修改后自动载入
"set history=2000 "history存储容量
set shortmess=aiI "启动不显示援助乌干达儿童
"设置退出vim后,内容显示在屏幕终端,可以查看或复制
"set t_ti= t_te=
set wildignore=*.swp,*.bak,*.pyc,*.class,.svn
""""""""""""""
"展示排版等界面设置
""""""""""""""
" 显示当前行号列号
set ruler
"状态栏显示正在输入的命令
"set showcmd
"左下角显示当前vim模式
"set showmode
"上下移动光标时,光标的上方或者下方至少会保留显示的行数
set scrolloff=7
"取消换行
set nowrap
"括号配对,跳转并高亮匹配的括号
set showmatch
"设置问内智能搜索提示
"高亮search命中的文本
set hlsearch
" 打开增量搜索模式,随着键入即时搜索
set incsearch
" 搜索时忽略大小写
set ignorecase
" 有一个或以上大写字母时仍大小写敏感
set smartcase
" 代码折叠
" 缩进配置
set smartindent " 智能缩进
set autoindent " 打开自动缩进
" tab相关
set tabstop=4 " 设置tab宽度等于4个空格
set shiftwidth=4 " 每一次缩进对应的空格数
set softtabstop=4 " 退格键可以一次删掉4个空格
set smarttab " 智能tab
set expandtab " 将tab自动转化成空格
""""""""""""""""""""""""""""
"文件编码,格式
"""""""""""""""""""""""""""
" 设置新文件的编码为 UTF_8
set encoding=utf-8
" 自动判断编码时,依次尝试以下编码:
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set helplang=cn
autocmd! bufwritepost .vimrc source % " vimrc文件修改之后自动加载。 linux。
"==========================================
" FileType Settings 文件类型设置
"==========================================
" Python 文件的一般设置,比如不要 tab 等
autocmd FileType python set tabstop=4 shiftwidth=4 expandtab ai
autocmd FileType ruby set tabstop=2 shiftwidth=2 softtabstop=2 expandtab ai
autocmd BufRead,BufNew *.md,*.mkd,*.markdown set filetype=markdown.mkd
" 保存python文件时删除多余空格
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfun
autocmd FileType c,cpp,java,go,php,javascript,puppet,python,rust,twig,xml,yml,perl autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces()
" 定义函数AutoSetFileHead,自动插入文件头
autocmd BufNewFile *.sh,*.py exec ":call AutoSetFileHead()"
function! AutoSetFileHead()
"如果文件类型为.sh文件
if &filetype == 'sh'
call setline(1, "\#!/bin/bash")
endif
"如果文件类型为python
if &filetype == 'python'
call setline(1, "\#!/usr/bin/env python")
call append(1, "\# encoding: utf-8")
endif
normal G
normal o
normal o
endfunc
" set some keyword to highlight
if has("autocmd")
" Highlight TODO, FIXME, NOTE, etc.
if v:version > 701
autocmd Syntax * call matchadd('Todo', '\W\zs\(TODO\|FIXME\|CHANGED\|DONE\|XXX\|BUG\|HACK\)')
autocmd Syntax * call matchadd('Debug', '\W\zs\(NOTE\|INFO\|IDEA\|NOTICE\)')
endif
endif
"=================================
"Install Plugins
"=================================
set nocompatible " be iMproved, required
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#rc()
" ################### 插件管理 ###################
" 使用Vundle来管理插件
" vim plugin bundle control, command model
" :BundleInstall install 安装配置的插件
" :BundleInstall! update 更新
" :BundleClean remove plugin not in list 删除本地无用插件
Bundle 'gmarik/vundle'
" ################### 基础 ######################
" 多语言语法检查
Bundle 'scrooloose/syntastic'
let g:syntastic_error_symbol='>>'
let g:syntastic_warning_symbol='>'
let g:syntastic_check_on_open=1
let g:syntastic_check_on_wq=0
let g:syntastic_enable_highlighting=1
" 最轻量
" let g:syntastic_python_checkers=['pyflakes'] " 使用pyflakes
" 中等
" error code: http://pep8.readthedocs.org/en/latest/intro.html#error-codes
let g:syntastic_python_checkers=['pyflakes', 'pep8'] " 使用pyflakes,速度比pylint快
let g:syntastic_python_pep8_args='--ignore=E501,E225,E124,E712'
let g:syntastic_javascript_checkers = ['jsl', 'jshint']
let g:syntastic_html_checkers=['tidy', 'jshint']
" 修改高亮的背景色, 适应主题
highlight SyntasticErrorSign guifg=white guibg=black
" to see error location list
let g:syntastic_always_populate_loc_list = 0
let g:syntastic_auto_loc_list = 0
let g:syntastic_loc_list_height = 5
function! ToggleErrors()
let old_last_winnr = winnr('$')
lclose
if old_last_winnr == winnr('$')
" Nothing was closed, open syntastic error location panel
Errors
endif
endfunction
nnoremap <Leader>s :call ToggleErrors()<cr>
" nnoremap <Leader>sn :lnext<cr>
" nnoremap <Leader>sp :lprevious<cr>
" 自动补全单引号,双引号等
Bundle 'Raimondi/delimitMate'
" 自动补全html/xml标签
Bundle 'docunext/closetag.vim'
let g:closetag_html_style=1
" 快速去行尾空格 [, + <Space>]
Bundle 'bronson/vim-trailing-whitespace'
map <leader><space> :FixWhitespace<cr>
" ################### 显示增强 ###################
Bundle 'airblade/vim-gitgutter'
let g:gitgutter_map_keys = 0
let g:gitgutter_enabled = 0
let g:gitgutter_highlight_lines = 1
nnoremap <leader>gs :GitGutterToggle<CR>
" 状态栏增强展示
" 新的airline配置
Bundle 'bling/vim-airline'
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_left_sep = '▶'
let g:airline_left_alt_sep = '❯'
let g:airline_right_sep = '◀'
let g:airline_right_alt_sep = '❮'
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.branch = '⎇'
" set status line
set laststatus=2
" 括号显示增强
Bundle 'kien/rainbow_parentheses.vim'
" 不加入这行, 防止黑色括号出现, 很难识别
" \ ['black', 'SeaGreen3'],
let g:rbpt_colorpairs = [
\ ['brown', 'RoyalBlue3'],
\ ['Darkblue', 'SeaGreen3'],
\ ['darkgray', 'DarkOrchid3'],
\ ['darkgreen', 'firebrick3'],
\ ['darkcyan', 'RoyalBlue3'],
\ ['darkred', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['brown', 'firebrick3'],
\ ['gray', 'RoyalBlue3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['Darkblue', 'firebrick3'],
\ ['darkgreen', 'RoyalBlue3'],
\ ['darkcyan', 'SeaGreen3'],
\ ['darkred', 'DarkOrchid3'],
\ ['red', 'firebrick3'],
\ ]
let g:rbpt_max = 16
let g:rbpt_loadcmd_toggle = 0
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces
" ################### 语言相关 ###################
Bundle 'thinca/vim-quickrun'
let g:quickrun_config = {
\ "_" : {
\ "outputter" : "message",
\ },
\}
let g:quickrun_no_default_key_mappings = 1
nmap <Leader>r <Plug>(quickrun)
map <F10> :QuickRun<CR>
" ###### Python #########
" python fly check, 弥补syntastic只能打开和保存才检查语法的不足
Bundle 'kevinw/pyflakes-vim'
let g:pyflakes_use_quickfix = 0
" for python.vim syntax highlight
Bundle 'hdima/python-syntax'
let python_highlight_all = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment