Skip to content

Instantly share code, notes, and snippets.

@erasin
Created February 5, 2018 15:12
Show Gist options
  • Save erasin/f3c0741062d5454675baee0a10f194cd to your computer and use it in GitHub Desktop.
Save erasin/f3c0741062d5454675baee0a10f194cd to your computer and use it in GitHub Desktop.
vimrc
call plug#begin('~/.vim/plugged')
Plug 'bling/vim-airline' | Plug 'vim-airline/vim-airline-themes'
Plug 'chriskempson/vim-tomorrow-theme'
Plug 'erasin/vim-one'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'majutsushi/tagbar'
Plug 'mhinz/vim-signify'
Plug 'tpope/vim-fugitive'
Plug 'scrooloose/syntastic'
Plug 'airblade/vim-gitgutter'
Plug 'mileszs/ack.vim'
Plug 'kien/ctrlp.vim' " 快速查询文件
Plug 'jiangmiao/auto-pairs' " 括号补全
Plug 'scrooloose/nerdcommenter' " 注释
Plug 'tpope/vim-surround'
Plug 'junegunn/vim-easy-align'
"Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
" Golang
Plug 'fatih/vim-go', { 'tag': '*' , 'for' : 'go' }
Plug 'nsf/gocode', { 'tag': '*' , 'for' : 'go' }
" Rust
Plug 'rust-lang/rust.vim', { 'for': 'rust' }
"Plug 'racer-rust/vim-racer',{ 'for' : 'rust' }
Plug 'mattn/webapi-vim'
Plug 'ekalinin/Dockerfile.vim', {'for' : 'Dockerfile'}
Plug 'fatih/vim-nginx' , {'for' : 'nginx'}
Plug 'toml-lang/toml',{'for': 'toml'}
Plug 'cespare/vim-toml',{'for': 'toml'}
Plug 'leafgarland/typescript-vim'
Plug 'stanangeloff/php.vim'
Plug '2072/php-indenting-for-vim'
Plug 'junegunn/goyo.vim', { 'for': 'markdown' }
" for yaovim
Plug 'rhysd/nyaovim-popup-tooltip'
call plug#end()
"=============================================
"set termguicolors
:let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1 " nvim 光标处理
set nocompatible
filetype on
filetype plugin on
filetype indent on
" === 基本设定 {{{
set noerrorbells " No beeps 取消警报
set number " Show line numbers 显示行号
set backspace=indent,eol,start " Makes backspace key more powerful.
set showcmd " Show me what I'm typing 显示命令
set showmode " Show current mode. 显示模式
set ts=4 " tabstop 4 tab键长
set softtabstop=4
set shiftwidth=4 " shift>> width
set expandtab " 使用空格来替换tab
set smarttab " 开启新行时使用智能 tab 缩进
set list " 显示Tab符,
set listchars=tab:\|\ , " 使用一高亮竖线代替 把符号显示为 |
" set listchars=tab:>-,trail:-
" set listchars=tab:\|\ ,nbsp:%,trail:-
set noswapfile " Don't use swapfil 不使用临时文件
set nobackup " Don't create annoying backup files 不创建备份文件
set splitright " Split vertical windows right to the current windows
set splitbelow " Split horizontal windows below to the current windows
set encoding=utf-8 " Set default encoding to UTF-8 设定默认编码
set fileencodings=utf-8,chinese,latin-1,cp936,euc-jp " 识别编码
set fileencoding=utf-8 " 设定文件编码
set autowrite " Automatically save before :next, :make etc. 自动保存在:next :make 命令执行
set autoread " Automatically reread changed files without asking me anything 自动加载变动
set laststatus=2 " 状态栏行高为2
set hidden
set fileformats=unix,dos,mac " Prefer Unix over Windows over OS 9 formats
" 复制
set clipboard^=unnamed
set clipboard^=unnamedplus
set noshowmatch " Do not show matching brackets by flickering
set nocursorcolumn
set noshowmode " We show the mode with airlien or lightline
set incsearch " Shows the match while typing
set hlsearch " Highlight found searches 搜索高亮,其对应 :nohlsearch
set ignorecase " Search case insensitive... 搜索过滤
set smartcase " ... but not when search pattern contains upper case characters
set ttyfast
"set ttymouse=xterm2
"set ttyscroll=3
set lazyredraw " Wait to redraw "
" speed up syntax highlighting
" 设置高亮
" set cursorcolumn
set cursorline
syntax sync minlines=256
set synmaxcol=300
set re=1
"set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P
" open help vertically
command! -nargs=* -complete=help Help vertical belowright help <args>
autocmd FileType help wincmd L
if has("gui")
"set guifont=Consolas\ for\ Powerline:h11
"set guifont=Noto\ Sans\ Mono\ CJK\ SC:h11
set guifont=Iosevka:h11
set clipboard+=unnamed
"set vb t_vb=
set guioptions-=m "no menu
set guioptions-=T "no toolbar
set guioptions-=l
set guioptions-=L
set guioptions-=r "no scrollbar
set guioptions-=R
"set background=light
set background=dark
let g:one_allow_italics = 1
"colorscheme Tomorrow
colorscheme one
let macvim_skip_colorscheme=1
"highlight SignColumn guibg=#272822
else
syntax enable
set guifont=Consolas\ for\ Powerline\ FixedD:h12
set background=dark
"set background=light
"colorscheme Tomorrow-Night
colorscheme one
endif
" This comes first, because we have mappings that depend on leader
" With a map leader it's possible to do extra key combinations
" i.e: <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","
" This trigger takes advantage of the fact that the quickfix window can be
" easily distinguished by its file-type, qf. The wincmd J command is
" equivalent to the Ctrl+W, Shift+J shortcut telling Vim to move a window to
" the very bottom (see :help :wincmd and :help ^WJ).
autocmd FileType qf wincmd J
"Dont show me any output when I build something
"Because I am using quickfix for errors
nmap <leader>m :make<CR><enter>
" Some useful quickfix shortcuts
":cc see the current error
":cn next error
":cp previous error
":clist list all errors
map <C-n> :cn<CR>
map <C-m> :cp<CR>
" simulate tab shortcuts
map gb :bnext<cr>
map gB :bprevious<cr>
nnoremap <silent> <leader>q :Sayonara<CR>
" Replace the current buffer with the given new file. That means a new file
" will be open in a buffer while the old one will be deleted
com! -nargs=1 -complete=file Breplace edit <args>| bdelete #
function! DeleteInactiveBufs()
"From tabpagebuflist() help, get a list of all buffers in all tabs
let tablist = []
for i in range(tabpagenr('$'))
call extend(tablist, tabpagebuflist(i + 1))
endfor
"Below originally inspired by Hara Krishna Dara and Keith Roberts
"http://tech.groups.yahoo.com/group/vim/message/56425
let nWipeouts = 0
for i in range(1, bufnr('$'))
if bufexists(i) && !getbufvar(i,"&mod") && index(tablist, i) == -1
"bufno exists AND isn't modified AND isn't in the list of buffers open in windows and tabs
silent exec 'bwipeout' i
let nWipeouts = nWipeouts + 1
endif
endfor
echomsg nWipeouts . ' buffer(s) wiped out'
endfunction
command! Ball :call DeleteInactiveBufs()
" Close quickfix easily
" 快速退出
nnoremap <leader>a :cclose<CR>
" 消除搜索高亮
nnoremap <leader><space> :nohlsearch<CR>
" Better split switching
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Fast saving
nmap <leader>w :w!<cr>
" Center the screen
nnoremap <space> zz
" Move up and down on splitted lines (on small width screens)
map <Up> gk
map <Down> gj
map k gk
map j gj
" Just go out in insert mode
imap jk <ESC>l
" Act like D and C
nnoremap Y y$
" ========== Steve Losh hacks ==========="
" Don't move on *
" I'd use a function for this but Vim clobbers the last search when you're in
" a function so fuck it, practicality beats purity.
nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr>
" iTerm2 is currently slow as balls at rendering the nice unicode lines, so for
" now I'll just use ASCII pipes. They're ugly but at least I won't want to kill
" myself when trying to move around a file.
set fillchars=diff:⣿,vert:│
set fillchars=diff:⣿,vert:\|
" Time out on key codes but not mappings.
" Basically this makes terminal Vim work sanely.
set notimeout
set ttimeout
set ttimeoutlen=10
" Better Completion
set complete=.,w,b,u,t
"set completeopt=longest,menuone
set completeopt=menu,longest
" Diffoff
nnoremap <leader>D :diffoff!<cr>
" Resize splits when the window is resized
au VimResized * :wincmd =
" }}}
" Visual Mode */# from Scrooloose {{{
function! s:VSetSearch()
let temp = @@
norm! gvy
let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
let @@ = temp
endfunction
vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR><c-o>
vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR><c-o>
" ----------------------------------------- "
" File Type settings "
" ----------------------------------------- "
au BufNewFile,BufRead *.vim setlocal noet ts=4 sw=4 sts=4
au BufNewFile,BufRead *.txt setlocal noet ts=4 sw=4
au BufNewFile,BufRead *.md setlocal noet ts=4 sw=4
augroup filetypedetect
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
au BufNewFile,BufRead .nginx.conf*,nginx.conf* setf nginx
" au BufNewFile,BufRead .rs setf rust
augroup END
au FileType nginx setlocal noet ts=4 sw=4 sts=4
" Wildmenu completion
set wildmenu
" set wildmode=list:longest
set wildmode=list:full
set wildignore+=.hg,.git,.svn " Version control
set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
set wildignore+=*.spl " compiled spelling word lists
set wildignore+=*.sw? " Vim swap files
set wildignore+=*.DS_Store " OSX bullshit
set wildignore+=*.luac " Lua byte code
set wildignore+=migrations " Django migrations
set wildignore+=go/pkg " Go static files
set wildignore+=go/bin " Go bin files
set wildignore+=go/bin-vagrant " Go bin-vagrant files
set wildignore+=*.pyc " Python byte code
set wildignore+=*.orig " Merge resolution files
" Prettify json
" comes with yajl, install: brew install yajl
" I don't use pythons json tool because it sorts the keys
com! JSONFormat %!json_reformat
" dict
autocmd FileType javascript set dictionary=~/.vim/dict/javascript.dict
autocmd FileType css set dictionary=~/.vim/dict/css.dict
autocmd FileType php set dictionary=~/.vim/dict/php_func_list.dict
"===================PLUG==========================
" ==================== NerdTree ====================
noremap <Leader>n :NERDTreeToggle<CR>
let NERDTreeWinSize = 32
let g:NERDTreeAutoDeleteBuffer = 1
let NERDTreeIgnore=['\.o$', '\.obj$', '\.py[co]$', '\~$', '\.swo$', '\.swp$', '^\.git$', '^\.hg$', '^\.svn$', '\.bzr$']
let g:nerdtree_tabs_autoclose = 1
" Auto refresh NERDTree
autocmd CursorHold,CursorHoldI * call Refresh()
" Inspired by https://github.com/Xuyuanp/nerdtree-git-plugin
function! Refresh()
if !exists('g:NERDTree') || !g:NERDTree.IsOpen()
return
endif
let winnr = winnr()
call g:NERDTree.CursorToTreeWin()
call b:NERDTree.root.refresh()
call b:NERDTree.root.refreshFlags()
call NERDTreeRender()
" Jump back
execute winnr . 'wincmd w'
"redraw
endfunction
" nerdtree-git-plugin
let g:NERDTreeIndicatorMapCustom = {
\ 'Modified' : '~',
\ "Staged" : '+',
\ 'Untracked' : '*',
\ 'Renamed' : '➜',
\ 'Unmerged' : '=',
\ 'Deleted' : '✖',
\ 'Dirty' : '~',
\ 'Clean' : '✔︎',
\ 'Unknown' : '?'
\ }
" ============= airline =================
"let g:airline_theme = 'solarized'
"let g:airline_theme = 'sol'
let g:airline_theme = 'one'
"let g:airline#extensions#tabline#enabled = 1
"let g:airline#extensions#tabline#left_sep = ' '
"let g:airline#extensions#tabline#left_alt_sep = '|'
" 显示 buffer 数字
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline_powerline_fonts=1
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
"设置顶部tabline栏符号显示"
let g:airline#extensions#tabline#left_sep = "\u2b80"
let g:airline#extensions#tabline#left_alt_sep = "\u2b81"
"设置状态栏符号显示,下面编码用双引号"
let g:Powerline_symbols="fancy"
let g:airline_symbols = {}
let g:airline_left_sep = "\u2b80"
let g:airline_left_alt_sep = "\u2b81"
let g:airline_right_sep = "\u2b82"
let g:airline_right_alt_sep = "\u2b83"
let g:airline_symbols.branch = "\u2b60"
let g:airline_symbols.readonly = "\u2b64"
let g:airline_symbols.linenr = "\u2b61"
let g:airline_extensions = ['branch', 'tabline']
" ==================== YouCompleteMe ====================
"let g:ycm_autoclose_preview_window_after_completion = 1
"let g:ycm_min_num_of_chars_for_completion = 1
"let g:ycm_server_keep_logfiles = 1
"let g:ycm_server_log_level = 'debug'
let g:ycm_python_binary_path= "/usr/local/bin/python3"
let g:ycm_rust_src_path = "/Users/erasin/Development/rust/crates/rust/src/"
let g:ycm_goto_buffer_command = 'vertical-split'
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
" ============== Shougo/neocomplete ===========
let g:neocomplete#enable_at_startup = 1
" ============ airblade/vim-gitgutter ========
let g:gitgutter_max_signs = 1000 " default value
" ==================== Vim-go ====================
let g:go_fmt_fail_silently = 0
let g:go_fmt_command = "goimports"
let g:go_autodetect_gopath = 1
" vim-go custom mappings
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>b <Plug>(go-build)
"au FileType go nmap <leader>t <Plug>(go-test)
au FileType go nmap <leader>c <Plug>(go-coverage)
au FileType go nmap <Leader>ds <Plug>(go-def-split)
au FileType go nmap <Leader>dv <Plug>(go-def-vertical)
au FileType go nmap <Leader>dt <Plug>(go-def-tab)
au FileType go nmap <Leader>gd <Plug>(go-doc)
au FileType go nmap <Leader>gv <Plug>(go-doc-vertical
au FileType go nmap <Leader>gb <Plug>(go-doc-browser)
au FileType go nmap <Leader>s <Plug>(go-implements)
au FileType go nmap <Leader>i <Plug>(go-info)
au FileType go nmap <Leader>e <Plug>(go-rename)
au FileType go nmap <Leader>got <Plug>(go-test)
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
let g:go_metalinter_enabled =1
let g:go_metalinter_autosave = 1
let g:go_metalinter_command = "vet"
let g:go_metalinter_autosave_enabled = ['vet', 'golint', 'test']
let g:syntastic_go_checkers = ['golint', 'govet', 'errcheck']
let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['go'] }
" ============ rust ==========================
let g:rustfmt_auto_save = 1
au FileType Rust nmap <leader>f :RustFmt<CR>
" ============ rust-racer ====================
"set hidden
let g:racer_cmd = "/Users/erasin/.cargo/bin/racer"
let $RUST_SRC_PATH="/Users/erasin/Development/rust/crates/rust/src/"
" ========== tagbar ========
" https://github.com/majutsushi/tagbar/wiki
noremap <leader>t :Tagbar<CR>
let tagbar_width = 32
" php
let g:tagbar_type_php = {
\ 'ctagstype' : 'php',
\ 'kinds' : [
\ 'f:function',
\ 'v:varliable',
\ 'c:const'
\ ],
\ "sort" : 0
\ }
" css
let g:tagbar_type_css = {
\ 'ctagstype' : 'Css',
\ 'kinds' : [
\ 'c:classes',
\ 's:selectors',
\ 'i:identities'
\ ]
\ }
" markdown
" add to ~/.ctags
" ----------------------------------------
"--langdef=markdown
"--langmap=markdown:.md
"--regex-markdown=/^(#+)[ \t]+([^#]*)/\1 \2/h,header,Markdown Headers/
"--regex-markdown=/\[([^\[]+)\]\(([^\)]+)\)/\1/l,link,Markdown Links/
"--regex-markdown=/!\[\]\(.*[\/ ](.*\.[a-z]{3})\)/\1/i,image,Markdown Image/
" ----------------------------------------
let g:tagbar_type_markdown = {
\ 'ctagstype' : 'markdown',
\ 'kinds' : [
\ 'h:headings',
\ 'l:links',
\ 'i:images'
\ ],
\ "sort" : 0
\ }
" rust
let g:tagbar_type_rust = {
\ 'ctagstype' : 'rust',
\ 'kinds' : [
\'T:types,type definitions',
\'f:functions,function definitions',
\'g:enum,enumeration names',
\'s:structure names',
\'m:modules,module names',
\'c:consts,static constants',
\'t:traits,traits',
\'i:impls,trait implementations',
\]
\}
" go get -u github.com/jstemmer/gotags
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
" ==================== CtrlP ====================
"let g:ctrlp_cmd = 'CtrlPMRU'
"let g:ctrlp_match_func = {'match' : 'matcher#cmatch'}
"let g:ctrlp_user_command = 'ag %s -l --nocolor --hidden -g ""'
"let g:ctrlp_working_path_mode = 'ra'
"let g:ctrlp_max_height = 10 " maxiumum height of match window
"let g:ctrlp_switch_buffer = 'et' " jump to a file if it's open already
"let g:ctrlp_mruf_max=450 " number of recently opened files
"let g:ctrlp_max_files=0 " do not limit the number of searchable files
"let g:ctrlp_use_caching = 1
"let g:ctrlp_clear_cache_on_exit = 0
"let g:ctrlp_cache_dir = $HOME.'/.cache/ctrlp'
let g:ctrlp_buftag_types = {
\ 'go' : '--language-force=go --golang-types=ftv',
\ 'coffee' : '--language-force=coffee --coffee-types=cmfvf',
\ 'markdown' : '--language-force=markdown --markdown-types=hik',
\ 'objc' : '--language-force=objc --objc-types=mpci',
\ 'rc' : '--language-force=rust --rust-types=fTm'
\ }
func! MyCtrlPTag()
let g:ctrlp_prompt_mappings = {
\ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
\ 'AcceptSelection("t")': ['<c-t>'],
\ }
CtrlPBufTag
endfunc
command! MyCtrlPTag call MyCtrlPTag()
nmap <C-f> :CtrlPCurWD<cr>
imap <C-f> <esc>:CtrlPCurWD<cr>
nmap <C-b> :CtrlPBuffer<cr>
imap <C-b> <esc>:CtrlPBuffer<cr>
" ================ vim room ===================
let g:vimroom_background = "light"
" ================ syntastic ==================
let g:syntatic_php_checkers = ['phpcs', 'php']
let g:syntastic_php_phpcs_args='--tab-width=0'
", 'phpcs']
"let g:syntastic_php_args = []
" ================== deoplete =================
let g:deoplete#enable_at_startup = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment