1 " ---------------------------------------------------------------------------
3 " ---------------------------------------------------------------------------
5 set nocompatible " essential
6 set history=1000 " lots of command line history
7 set confirm " error files / jumping
8 set fileformats=unix,dos,mac " support these files
9 set iskeyword+=_,$,@,%,#,- " none word dividers
10 set viminfo='1000,f1,:100,@100,/20
11 set modeline " make sure modeline support is enabled
12 set autoread " reload files (no local changes only)
14 " ---------------------------------------------------------------------------
16 " ---------------------------------------------------------------------------
18 call plug#begin('~/.vim/plugged')
21 Plug 'ajmwagar/vim-deus'
22 Plug 'AlessandroYorba/Despacio'
23 Plug 'altercation/vim-colors-solarized'
24 Plug 'jacoborus/tender.vim'
25 Plug 'jnurmine/Zenburn'
26 Plug 'junegunn/seoul256.vim'
27 Plug 'Lokaltog/vim-distinguished'
28 Plug 'mhartington/oceanic-next'
29 Plug 'morhetz/gruvbox'
30 Plug 'rakr/vim-two-firewatch'
31 Plug 'vim-scripts/rdark-terminal2.vim'
32 Plug 'vim-scripts/twilight256.vim'
33 Plug 'yorickpeterse/happy_hacking.vim'
34 Plug 'yuttie/hydrangea-vim'
35 Plug 'zacanger/angr.vim'
38 Plug 'airblade/vim-gitgutter' " shows git diff in the gutter
39 Plug 'farmergreg/vim-lastplace' " intelligently reopen files at your last edit position
40 Plug 'godlygeek/csapprox' " make gui-only colorschemes work automagically in terminal vim
41 Plug 'junegunn/goyo.vim' " distraction-free writing
42 Plug 'junegunn/limelight.vim' " hyperfocus-writing
43 Plug 'kien/ctrlp.vim' " fuzzy file, buffer, mru, etc finder
44 Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " file system explorer
45 Plug 'sjl/gundo.vim' " visualize undo tree
46 Plug 'vim-airline/vim-airline' " lean & mean status/tabline
47 Plug 'vim-airline/vim-airline-themes' " themes for vim-airline
50 Plug 'ludovicchabant/vim-gutentags' " automatic ctags
51 Plug 'mileszs/ack.vim' " Ack wrapper
52 Plug 'tpope/vim-fugitive' " Git wrappers
55 Plug 'tpope/vim-surround' " quoting/parenthesizing made simple
56 Plug 'tpope/vim-unimpaired' " pairs of handy bracket mappings
59 Plug 'tpope/vim-git' " filetype=gitcommit
60 Plug 'vim-pandoc/vim-pandoc'
61 Plug 'vim-pandoc/vim-pandoc-syntax' " filetype=markdown
62 Plug '~/.vim/bundle/mumps' " filetype=mumps
65 Plug 'kopischke/vim-fetch' " handle opening filenames with line+column numbers
66 Plug 'tpope/vim-scriptease' " misc collection of helper commands
67 Plug '~/.vim/bundle/airlinetheme-map' " override AirlineTheme for certain colorscheme's
68 Plug '~/.vim/bundle/autofolds' " folds for my *rc files
73 if empty(glob('~/.vim/plugged'))
74 autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
77 " ----------------------------------------------------------------------------
79 " ----------------------------------------------------------------------------
82 let NERDTreeShowHidden=1 " show dotfiles by default
83 let NERDTreeMinimalUI=1 " disable 'Press ? for help' text
87 let g:ctrlp_show_hidden = 1
88 let g:ctrlp_cache_dir = $HOME.'/.vim/.cache/ctrlp'
89 let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
92 let g:airline_mode_map = {
105 if !exists('g:airline_symbols')
106 let g:airline_symbols = {}
108 if has("gui_running")
109 let g:airline_powerline_fonts = 1 " use powerline font symbols
111 let g:airline_symbols_ascii = 1 " use plain ascii symbols
112 let g:airline_symbols.branch = 'BR:'
114 let g:airline_symbols.linenr = ''
115 let g:airline_symbols.maxlinenr = ''
118 let g:gitgutter_enabled = 0 " disable by default
121 let g:goyo_width = 80
122 let g:limelight_conceal_ctermfg = 240
123 let g:limelight_default_coefficient = 0.6
124 let g:limelight_paragraph_span = 1 " show adjacent paragraphs
125 let g:limelight_priority = -1 " don't overrule hlsearch
127 function! s:goyo_enter()
129 silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
135 function! s:goyo_leave()
137 silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
143 autocmd! User GoyoEnter nested call <SID>goyo_enter()
144 autocmd! User GoyoLeave nested call <SID>goyo_leave()
147 let g:pandoc#syntax#conceal#use = 0 " disable conceal pretty display
148 let g:pandoc#folding#fdc = 0 " disable foldcolumn
149 let g:pandoc#folding#level = 6 " open all folds by default
152 let g:gutentags_enabled_user_func = 'GutentagsCheckEnabled'
153 function! GutentagsCheckEnabled(file)
154 let file_path = fnamemodify(a:file, ':p:h')
156 " enable gutentags if ctags file already exists
157 " tip: `touch tags` in project root to enable gutentags auto-updating
159 let gutentags_root = gutentags#get_project_root(file_path)
160 if filereadable(gutentags_root . '/tags')
169 " ---------------------------------------------------------------------------
171 " ---------------------------------------------------------------------------
173 if !has("gui_running") && !(&term =~ '256color')
174 if has("terminfo") && ! (&term == 'linux' || &term == 'Eterm' || &term == 'vt220' || &term == 'nsterm-16color' || &term == 'xterm-16color')
175 " Force these terminals to accept my authority! (default)
177 set t_AB=
\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm " ANSI background
178 set t_AF=
\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm " ANSI foreground
179 elseif &term == 'term' || &term == 'rxvt' || &term == 'vt100' || &term == 'screen'
180 " Less-Cool Terminals (no terminfo)
182 set t_AB=
\e[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
183 set t_AF=
\e[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
185 " Terminals that have trustworthy terminfo entries
188 set t_Sf=
\e[3%dm " foreground
189 set t_Sb=
\e[4%dm " background
190 elseif $TERM == 'xterm'
196 " ---------------------------------------------------------------------------
198 " ---------------------------------------------------------------------------
200 if &t_Co > 2 || has("gui_running")
201 set background=dark " dark background
202 syntax enable " syntax highligting
204 " override colors in solarized colorscheme
205 augroup vimrc_colorscheme_solarized
207 if !has("gui_running")
208 " override Normal ctermfg
209 autocmd ColorScheme solarized highlight Normal ctermfg=None
210 " override Comment ctermfg
212 autocmd ColorScheme solarized highlight Comment ctermfg=241
214 autocmd ColorScheme solarized highlight Comment ctermfg=DarkGrey
216 " override visual block
217 autocmd ColorScheme solarized highlight Visual term=reverse cterm=reverse ctermfg=DarkGreen ctermbg=White
219 " override unprintable chars (listchars)
220 autocmd ColorScheme solarized highlight SpecialKey ctermfg=DarkGrey ctermbg=Black
225 " colorscheme theme options
226 let g:solarized_termcolors=&t_Co " use 256 colors for solarized
227 let g:solarized_termtrans=1
229 if !exists('s:set_colorscheme')
230 colorscheme solarized
231 let s:set_colorscheme=1
234 " airline theme options
235 let g:solarized16_termcolors=16 " always use 16 colors for 'solarized16' vim-airline theme
236 let g:colorscheme_airlinetheme_map = {
237 \ 'seoul256-light': 'zenburn',
238 \ 'solarized': 'solarized16',
240 let g:colorscheme_airlinetheme_default = 'distinguished'
244 " ----------------------------------------------------------------------------
246 " ----------------------------------------------------------------------------
248 set nobackup " do not keep backups after close
249 set nowritebackup " do not keep a backup while working
250 set backupcopy=yes " keep attributes of original file
251 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
252 set directory=.,~/tmp,~/.vim/swap " swap file directory-order
253 set updatetime=1000 " idle time before writing swap file to disk
255 " ----------------------------------------------------------------------------
257 " ----------------------------------------------------------------------------
259 set ruler " show the cursor position all the time
260 set showcmd " display incomplete commands
261 set nolazyredraw " turn off lazy redraw
262 set hidden " keep buffers loaded when hidden
263 set showmode " show mode at bottom of screen
264 set wildmenu " turn on wild menu
265 set wildmode=list:longest,full
266 set cmdheight=2 " command line height
267 set backspace=2 " allow backspacing over everything in insert mode
268 set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
269 set shortmess=filtIoO " shorten messages
270 set report=0 " tell us about changes
271 set nostartofline " don't jump to the start of line when scrolling
272 set scrolloff=4 " vertical padding
273 set sidescroll=40 " side-scrolling increment (for nowrap mode)
274 set sidescrolloff=10 " horz padding
275 set tabpagemax=15 " open 15 tabs max
276 set splitright " put new vsplit windows to the right of the current
278 " ----------------------------------------------------------------------------
280 " ----------------------------------------------------------------------------
282 set showmatch " brackets/braces that is
283 set matchtime=5 " duration to show matching brace (1/10 sec)
284 set incsearch " do incremental searching
285 set laststatus=2 " always show the status line
286 set ignorecase " ignore case when searching
287 set smartcase " case-sensitive if search contains an uppercase character
288 set visualbell " shut the heck up
289 set hlsearch " highlight all search matches
290 set list listchars=trail:·,tab:▸\ ,precedes:<,extends:> " show trailing whitespace and tab chars
292 " ----------------------------------------------------------------------------
294 " ----------------------------------------------------------------------------
296 if !exists(':AirlineTheme')
297 set statusline=%1*\ %n%0*\ %<%f " buffer #, filename
298 set statusline+=\ %h%m%r " file-state flags
299 set statusline+=%= " left-right divider
300 set statusline+=%{strlen(&fenc)?&fenc:&enc},%{&ff}\ %y " file-encoding, format, type
301 set statusline+=\ %12.(%v,%l/%L%)\ \ %-4P " cursor position, % through file of viewport
304 " ----------------------------------------------------------------------------
306 " ----------------------------------------------------------------------------
308 set autoindent " automatic indent new lines
309 set smartindent " be smart about it
310 set nowrap " do not wrap lines
311 set softtabstop=2 " yep, two
312 set shiftwidth=2 " ..
314 set expandtab " expand tabs to spaces
315 set smarttab " smarter softtab handling
316 set formatoptions+=n " support for numbered/bullet lists
317 set textwidth=0 " no line-wrapping by default
318 set virtualedit=block " allow virtual edit in visual block ..
319 set spelllang=en_us " spell-check dictionary
321 " ----------------------------------------------------------------------------
322 " Filename Exclusions
323 " ----------------------------------------------------------------------------
325 set wildignore+=.hg,.git,.svn " version control directories
326 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png " image files
327 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
328 set wildignore+=*.pyc " Python byte code
329 set wildignore+=*.sw? " Vim swap files
330 set wildignore+=.DS_Store " OSX junk
332 " ----------------------------------------------------------------------------
334 " ----------------------------------------------------------------------------
336 " movement based on display lines not physical lines (sane movement with wrap turned on)
345 inoremap <Down> <C-o>gj
346 inoremap <Up> <C-o>gk
347 " do not menu with left / right in command line
348 cnoremap <Left> <Space><BS><Left>
349 cnoremap <Right> <Space><BS><Right>
351 " reflow paragraph with Q in normal and visual mode
354 " remap U to <C-r> for easier redo
356 " make Y consistent with C (c$) and D (d$)
358 " disable default vim regex handling for searching
361 " reselect visual block after indent/outdent
365 " <Space> to turn off highlighting and clear any message already displayed.
366 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
368 " leader-based keyboard shortcuts
371 nmap <leader>b :CtrlPBuffer<CR>
372 nmap <leader>o :CtrlP<CR>
373 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
375 nmap <leader>d :NERDTreeToggle<CR>
376 nmap <leader>f :NERDTreeFind<CR>
378 nmap <leader>u :GundoToggle<CR>
380 nmap <leader>gb :Gblame<CR>
381 nmap <leader>gs :Gstatus<CR>
382 nmap <leader>gd :Gdiff<CR>
383 nmap <leader>gl :Glog<CR>
384 nmap <leader>gc :Gcommit<CR>
385 nmap <leader>gp :Gpush<CR>
386 " cd to the directory containing the file in the buffer
387 nmap <leader>cd :lcd %:h<CR>
388 " toggle quickfix window
389 function! QuickfixToggle()
390 let wcnt_old = winnr("$")
392 let wcnt_cur = winnr("$")
393 if wcnt_old == wcnt_cur
397 nmap <leader>cc :call QuickfixToggle()<CR>
398 " toggle diffmode for a buffer
399 function! DiffToggle()
406 nmap <leader>df :call DiffToggle()<CR>
407 " quickly edit/reload vimrc
408 nmap <leader>ev :edit $MYVIMRC<CR>
409 nmap <leader>sv :source $MYVIMRC<CR>
410 " find merge conflict markers
411 nmap <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
413 nnoremap <leader>h1 m`yypVr=``
414 nnoremap <leader>h2 m`yypVr-``
415 nnoremap <leader>h3 m`^i### <esc>``4l
416 nnoremap <leader>h4 m`^i#### <esc>``5l
417 nnoremap <leader>h5 m`^i##### <esc>``6l
419 nmap <leader>hls :set hlsearch! hlsearch?<CR>
421 nmap <leader>wu mQviwU`Q
422 nmap <leader>wl mQviwu`Q
423 " upper/lower first char of word
424 nmap <leader>wU mQgewvU`Q
425 nmap <leader>wL mQgewvu`Q
426 " smart paste - enable paste-mode and paste contents of system clipboard
427 map <leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
429 nmap <leader>sp :setlocal spell! spell?<CR>
430 " set text wrapping toggles
431 nmap <leader>tw :set wrap! wrap?<CR>
432 " set list-whitespace-chars toggle
433 nmap <leader>ws :set list! list?<CR>
434 " open tag definition in a horz split
435 nmap <leader>tag :split <CR>:exec("tag ".expand("<cword>"))<CR>
437 nmap <leader>ht :GitGutterToggle<CR>
438 nmap <leader>hp <Plug>GitGutterPreviewHunk
439 nmap <leader>hu <Plug>GitGutterUndoHunk
440 nmap <leader>hs <Plug>GitGutterStageHunk
442 nnoremap <leader>G :Goyo<CR>
444 " --------------------------------------------------------------------------
446 " --------------------------------------------------------------------------
449 " Run vim command, redirect output to a scratch buffer
450 function! s:redir(cmd)
458 setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified
463 command! -nargs=+ -complete=command Redir call s:redir(<q-args>)
466 " Make a scratch buffer with all of the leader keybindings.
467 command! ListLeaders :call s:redir('nmap <leader>')
470 " Use `git grep` to search for to-do comments, add matches to qflist
471 function! s:todo() abort
473 for cmd in ['git grep -nI -e TODO -e FIXME -e XXX 2> /dev/null',
474 \ 'grep -rnI -e TODO -e FIXME -e XXX * 2> /dev/null']
475 let lines = split(system(cmd), '\n')
476 if v:shell_error != 0 | continue | endif
478 let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3]
479 call add(entries, { 'filename': fname, 'lnum': lno, 'text': text })
485 call setqflist(entries)
489 command! Todo call s:todo()
491 " :StripTrailingWhitespace
492 " Strip trailing whitespace
493 function! StripTrailingWhitespace()
494 " preparation: save last search, and cursor position.
500 " clean up: restore previous search history, and cursor position
504 command! StripTrailingWhitespace call StripTrailingWhitespace()
506 " ---------------------------------------------------------------------------
507 " Auto Commands / File Types
508 " ---------------------------------------------------------------------------
510 " override Filetype settings
511 augroup vimrc_filetype
514 au Filetype sh,bash setlocal ts=4 sts=4 sw=4 expandtab
516 " git commit message: enable spell checking
517 au Filetype gitcommit setlocal spell
518 " gitconfig file: use real tabs
519 au Filetype gitconfig setlocal noexpandtab
520 " javascript: don't use cindent
521 au FileType javascript setlocal nocindent
522 " makefiles: use real tabs
523 au FileType make setlocal noexpandtab
525 au FileType vim setlocal foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum) foldtext=autofolds#foldtext() foldlevel=2
526 au FileType sh setlocal foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum,'sh') foldtext=autofolds#foldtext() foldlevel=2
529 " --------------------------------------------------------------------------
531 " --------------------------------------------------------------------------
533 if filereadable(glob("~/.vimrc.local"))
534 source ~/.vimrc.local