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 'tonyduckles/vim-colorschemes'
24 Plug 'airblade/vim-gitgutter' " shows git diff in the gutter
25 Plug 'farmergreg/vim-lastplace' " intelligently reopen files at your last edit position
26 Plug 'godlygeek/csapprox' " make gui-only colorschemes work automagically in terminal vim
27 Plug 'junegunn/goyo.vim' " distraction-free writing
28 Plug 'junegunn/limelight.vim' " hyperfocus-writing
29 Plug 'kien/ctrlp.vim' " fuzzy file, buffer, mru, etc finder
30 Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " file system explorer
31 Plug 'sjl/gundo.vim' " visualize undo tree
32 Plug 'vim-airline/vim-airline' " lean & mean status/tabline
33 Plug 'vim-airline/vim-airline-themes' " themes for vim-airline
36 Plug 'ludovicchabant/vim-gutentags' " automatic ctags
37 Plug 'mileszs/ack.vim' " Ack wrapper
38 Plug 'tpope/vim-fugitive' " Git wrappers
41 Plug 'tpope/vim-surround' " quoting/parenthesizing made simple
42 Plug 'tpope/vim-unimpaired' " pairs of handy bracket mappings
45 Plug 'tpope/vim-git' " filetype=gitcommit
46 Plug 'vim-pandoc/vim-pandoc'
47 Plug 'vim-pandoc/vim-pandoc-syntax' " filetype=markdown
48 Plug '~/.vim/bundle/mumps' " filetype=mumps
51 Plug 'kopischke/vim-fetch' " handle opening filenames with line+column numbers
52 Plug 'tpope/vim-scriptease' " misc collection of helper commands
53 Plug '~/.vim/bundle/airlinetheme-map' " override AirlineTheme for certain colorscheme's
54 Plug '~/.vim/bundle/autofolds' " folds for my *rc files
59 if empty(glob('~/.vim/plugged'))
60 autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
63 " ----------------------------------------------------------------------------
65 " ----------------------------------------------------------------------------
68 let NERDTreeShowHidden=1 " show dotfiles by default
69 let NERDTreeMinimalUI=1 " disable 'Press ? for help' text
73 let g:ctrlp_show_hidden = 1
74 let g:ctrlp_cache_dir = $HOME.'/.vim/.cache/ctrlp'
75 let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
78 let g:airline_mode_map = {
91 if !exists('g:airline_symbols')
92 let g:airline_symbols = {}
95 let g:airline_powerline_fonts = 1 " use powerline font symbols
97 let g:airline_symbols_ascii = 1 " use plain ascii symbols
98 let g:airline_symbols.branch = ''
100 let g:airline_symbols.dirty = '*'
101 let g:airline_symbols.linenr = ''
102 let g:airline_symbols.maxlinenr = ''
103 let g:airline_symbols.notexists = '?'
106 let g:gitgutter_enabled = 0 " disable by default
109 let g:goyo_width = 80
110 let g:limelight_conceal_ctermfg = 240
111 let g:limelight_default_coefficient = 0.6
112 let g:limelight_paragraph_span = 1 " show adjacent paragraphs
113 let g:limelight_priority = -1 " don't overrule hlsearch
115 function! s:goyo_enter()
117 silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
123 function! s:goyo_leave()
125 silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
131 autocmd! User GoyoEnter nested call <SID>goyo_enter()
132 autocmd! User GoyoLeave nested call <SID>goyo_leave()
135 let g:pandoc#syntax#conceal#use = 0 " disable conceal pretty display
136 let g:pandoc#folding#fdc = 0 " disable foldcolumn
137 let g:pandoc#folding#level = 6 " open all folds by default
140 let g:gutentags_enabled_user_func = 'GutentagsCheckEnabled'
141 function! GutentagsCheckEnabled(file)
142 let file_path = fnamemodify(a:file, ':p:h')
144 " enable gutentags if ctags file already exists
145 " tip: `touch tags` in project root to enable gutentags auto-updating
147 let gutentags_root = gutentags#get_project_root(file_path)
148 if filereadable(gutentags_root . '/tags')
157 " ---------------------------------------------------------------------------
159 " ---------------------------------------------------------------------------
161 if !has("gui_running") && !(&term =~ '256color')
162 if has("terminfo") && ! (&term == 'linux' || &term == 'Eterm' || &term == 'vt220' || &term == 'nsterm-16color' || &term == 'xterm-16color')
163 " Force these terminals to accept my authority! (default)
165 set t_AB=
\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm " ANSI background
166 set t_AF=
\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm " ANSI foreground
167 elseif &term == 'term' || &term == 'rxvt' || &term == 'vt100' || &term == 'screen'
168 " Less-Cool Terminals (no terminfo)
170 set t_AB=
\e[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
171 set t_AF=
\e[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
173 " Terminals that have trustworthy terminfo entries
176 set t_Sf=
\e[3%dm " foreground
177 set t_Sb=
\e[4%dm " background
178 elseif $TERM == 'xterm'
184 " ---------------------------------------------------------------------------
186 " ---------------------------------------------------------------------------
188 if &t_Co > 2 || has("gui_running")
189 set background=dark " dark background
190 syntax enable " syntax highligting
192 " override colors in solarized colorscheme
193 augroup vimrc_colorscheme_solarized
195 if !has("gui_running")
196 " override Normal ctermfg
197 autocmd ColorScheme solarized highlight Normal ctermfg=None
198 " override Comment ctermfg
200 autocmd ColorScheme solarized highlight Comment ctermfg=241
202 autocmd ColorScheme solarized highlight Comment ctermfg=DarkGrey
204 " override visual block
205 autocmd ColorScheme solarized highlight Visual term=reverse cterm=reverse ctermfg=DarkGreen ctermbg=White
207 " override unprintable chars (listchars)
208 autocmd ColorScheme solarized highlight SpecialKey ctermfg=DarkGrey ctermbg=Black
213 " colorscheme theme options
214 let g:solarized_termcolors=&t_Co " use 256 colors for solarized
215 let g:solarized_termtrans=1
217 if !exists('s:set_colorscheme')
218 colorscheme solarized
219 let s:set_colorscheme=1
222 " airline theme options
223 let g:solarized16_termcolors=16 " always use 16 colors for 'solarized16' vim-airline theme
224 let g:colorscheme_airlinetheme_map = {
225 \ 'seoul256-light': 'zenburn',
226 \ 'solarized': 'solarized16',
228 let g:colorscheme_airlinetheme_default = 'distinguished'
232 " ----------------------------------------------------------------------------
234 " ----------------------------------------------------------------------------
236 set nobackup " do not keep backups after close
237 set nowritebackup " do not keep a backup while working
238 set backupcopy=yes " keep attributes of original file
239 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
240 set directory=.,~/tmp,~/.vim/swap " swap file directory-order
241 set updatetime=1000 " idle time before writing swap file to disk
243 " ----------------------------------------------------------------------------
245 " ----------------------------------------------------------------------------
247 set ruler " show the cursor position all the time
248 set showcmd " display incomplete commands
249 set nolazyredraw " turn off lazy redraw
250 set hidden " keep buffers loaded when hidden
251 set showmode " show mode at bottom of screen
252 set wildmenu " turn on wild menu
253 set wildmode=list:longest,full
254 set cmdheight=2 " command line height
255 set backspace=2 " allow backspacing over everything in insert mode
256 set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
257 set shortmess=filtIoO " shorten messages
258 set report=0 " tell us about changes
259 set nostartofline " don't jump to the start of line when scrolling
260 set scrolloff=4 " vertical padding
261 set sidescroll=40 " side-scrolling increment (for nowrap mode)
262 set sidescrolloff=10 " horz padding
263 set tabpagemax=15 " open 15 tabs max
264 set splitright " put new vsplit windows to the right of the current
266 " ----------------------------------------------------------------------------
268 " ----------------------------------------------------------------------------
270 set showmatch " brackets/braces that is
271 set matchtime=5 " duration to show matching brace (1/10 sec)
272 set incsearch " do incremental searching
273 set laststatus=2 " always show the status line
274 set ignorecase " ignore case when searching
275 set smartcase " case-sensitive if search contains an uppercase character
276 set visualbell " shut the heck up
277 set hlsearch " highlight all search matches
278 set list listchars=trail:·,tab:▸\ ,precedes:<,extends:> " show trailing whitespace and tab chars
280 " ----------------------------------------------------------------------------
282 " ----------------------------------------------------------------------------
284 if !exists(':AirlineTheme')
285 set statusline=%1*\ %n%0*\ %<%f " buffer #, filename
286 set statusline+=\ %h%m%r " file-state flags
287 set statusline+=%= " left-right divider
288 set statusline+=%{strlen(&fenc)?&fenc:&enc},%{&ff}\ %y " file-encoding, format, type
289 set statusline+=\ %12.(%v,%l/%L%)\ \ %-4P " cursor position, % through file of viewport
292 " ----------------------------------------------------------------------------
294 " ----------------------------------------------------------------------------
296 set autoindent " automatic indent new lines
297 set smartindent " be smart about it
298 set nowrap " do not wrap lines
299 set softtabstop=2 " yep, two
300 set shiftwidth=2 " ..
302 set expandtab " expand tabs to spaces
303 set smarttab " smarter softtab handling
304 set formatoptions+=n " support for numbered/bullet lists
305 set textwidth=0 " no line-wrapping by default
306 set virtualedit=block " allow virtual edit in visual block ..
307 set spelllang=en_us " spell-check dictionary
309 " ----------------------------------------------------------------------------
310 " Filename Exclusions
311 " ----------------------------------------------------------------------------
313 set wildignore+=.hg,.git,.svn " version control directories
314 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png " image files
315 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
316 set wildignore+=*.pyc " Python byte code
317 set wildignore+=*.sw? " Vim swap files
318 set wildignore+=.DS_Store " OSX junk
320 " ----------------------------------------------------------------------------
322 " ----------------------------------------------------------------------------
324 " movement based on display lines not physical lines (sane movement with wrap turned on)
333 inoremap <Down> <C-o>gj
334 inoremap <Up> <C-o>gk
335 " do not menu with left / right in command line
336 cnoremap <Left> <Space><BS><Left>
337 cnoremap <Right> <Space><BS><Right>
339 " reflow paragraph with Q in normal and visual mode
342 " remap U to <C-r> for easier redo
344 " make Y consistent with C (c$) and D (d$)
346 " disable default vim regex handling for searching
349 " reselect visual block after indent/outdent
353 " <Space> to turn off highlighting and clear any message already displayed.
354 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
356 " leader-based keyboard shortcuts
359 nmap <leader>b :CtrlPBuffer<CR>
360 nmap <leader>o :CtrlP<CR>
361 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
363 nmap <leader>d :NERDTreeToggle<CR>
364 nmap <leader>f :NERDTreeFind<CR>
366 nmap <leader>u :GundoToggle<CR>
368 nmap <leader>gb :Gblame<CR>
369 nmap <leader>gs :Gstatus<CR>
370 nmap <leader>gd :Gdiff<CR>
371 nmap <leader>gl :Glog<CR>
372 nmap <leader>gc :Gcommit<CR>
373 nmap <leader>gp :Gpush<CR>
374 " cd to the directory containing the file in the buffer
375 nmap <leader>cd :lcd %:h<CR>
376 " toggle quickfix window
377 function! QuickfixToggle()
378 let wcnt_old = winnr("$")
380 let wcnt_cur = winnr("$")
381 if wcnt_old == wcnt_cur
385 nmap <leader>q :call QuickfixToggle()<CR>
386 " toggle diffmode for a buffer
387 function! DiffToggle()
394 nmap <leader>df :call DiffToggle()<CR>
395 " quickly edit/reload vimrc
396 nmap <leader>ev :edit $MYVIMRC<CR>
397 nmap <leader>sv :source $MYVIMRC<CR>
398 " find merge conflict markers
399 nmap <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
401 nnoremap <leader>h1 m`yypVr=``
402 nnoremap <leader>h2 m`yypVr-``
403 nnoremap <leader>h3 m`^i### <esc>``4l
404 nnoremap <leader>h4 m`^i#### <esc>``5l
405 nnoremap <leader>h5 m`^i##### <esc>``6l
407 nmap <leader>hls :set hlsearch! hlsearch?<CR>
409 nmap <leader>wu mQviwU`Q
410 nmap <leader>wl mQviwu`Q
411 " upper/lower first char of word
412 nmap <leader>wU mQgewvU`Q
413 nmap <leader>wL mQgewvu`Q
414 " smart paste - enable paste-mode and paste contents of system clipboard
415 map <leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
417 nmap <leader>sp :setlocal spell! spell?<CR>
418 " set text wrapping toggles
419 nmap <leader>tw :set wrap! wrap?<CR>
420 " set list-whitespace-chars toggle
421 nmap <leader>ws :set list! list?<CR>
422 " open tag definition in a horz split
423 nmap <leader>tag :split <CR>:exec("tag ".expand("<cword>"))<CR>
425 nmap <leader>ht :GitGutterToggle<CR>
426 nmap <leader>hp <Plug>GitGutterPreviewHunk
427 nmap <leader>hu <Plug>GitGutterUndoHunk
428 nmap <leader>hs <Plug>GitGutterStageHunk
430 nnoremap <leader>G :Goyo<CR>
432 " --------------------------------------------------------------------------
434 " --------------------------------------------------------------------------
437 " Run vim command, redirect output to a scratch buffer
438 function! s:redir(cmd)
446 setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified
451 command! -nargs=+ -complete=command Redir call s:redir(<q-args>)
454 " Make a scratch buffer with all of the leader keybindings.
455 command! ListLeaders :call s:redir('nmap <leader>')
458 " Use `git grep` to search for to-do comments, add matches to qflist
459 function! s:todo() abort
461 for cmd in ['git grep -nI -e TODO -e FIXME -e XXX 2> /dev/null',
462 \ 'grep -rnI -e TODO -e FIXME -e XXX * 2> /dev/null']
463 let lines = split(system(cmd), '\n')
464 if v:shell_error != 0 | continue | endif
466 let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3]
467 call add(entries, { 'filename': fname, 'lnum': lno, 'text': text })
473 call setqflist(entries)
477 command! Todo call s:todo()
479 " :StripTrailingWhitespace
480 " Strip trailing whitespace
481 function! StripTrailingWhitespace()
482 " preparation: save last search, and cursor position.
488 " clean up: restore previous search history, and cursor position
492 command! StripTrailingWhitespace call StripTrailingWhitespace()
494 " ---------------------------------------------------------------------------
495 " Auto Commands / File Types
496 " ---------------------------------------------------------------------------
498 " override Filetype settings
499 augroup vimrc_filetype
502 au Filetype sh,bash setlocal ts=4 sts=4 sw=4 expandtab
504 " git commit message: enable spell checking
505 au Filetype gitcommit setlocal spell
506 " gitconfig file: use real tabs
507 au Filetype gitconfig setlocal noexpandtab
508 " javascript: don't use cindent
509 au FileType javascript setlocal nocindent
510 " makefiles: use real tabs
511 au FileType make setlocal noexpandtab
513 au FileType vim setlocal foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum) foldtext=autofolds#foldtext() foldlevel=2
514 au FileType sh setlocal foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum,'sh') foldtext=autofolds#foldtext() foldlevel=2
517 " --------------------------------------------------------------------------
519 " --------------------------------------------------------------------------
521 if filereadable(glob("~/.vimrc.local"))
522 source ~/.vimrc.local