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 'AlessandroYorba/Despacio'
 
  22 Plug 'altercation/vim-colors-solarized'
 
  23 Plug 'junegunn/seoul256.vim'
 
  24 Plug 'morhetz/gruvbox'
 
  25 Plug 'yuttie/hydrangea-vim'
 
  28 Plug 'airblade/vim-gitgutter'         " shows git diff in the gutter
 
  29 Plug 'junegunn/goyo.vim'              " distraction-free writing
 
  30 Plug 'junegunn/limelight.vim'         " hyperfocus-writing
 
  31 Plug 'kien/ctrlp.vim'                 " fuzzy file, buffer, mru, etc finder
 
  32 Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }  " file system explorer
 
  33 Plug 'sjl/gundo.vim'                  " visualize undo tree
 
  34 Plug 'vim-airline/vim-airline'        " lean & mean status/tabline
 
  35 Plug 'vim-airline/vim-airline-themes' " themes for vim-airline
 
  38 Plug 'mileszs/ack.vim'                " Ack wrapper
 
  39 Plug 'tpope/vim-fugitive'             " Git wrappers
 
  42 Plug 'tpope/vim-surround'             " quoting/parenthesizing made simple
 
  43 Plug 'tpope/vim-unimpaired'           " pairs of handy bracket mappings
 
  46 Plug 'tpope/vim-git'                  " filetype=gitcommit
 
  47 Plug 'vim-pandoc/vim-pandoc'
 
  48 Plug 'vim-pandoc/vim-pandoc-syntax'   " filetype=markdown
 
  49 Plug '~/.vim/bundle/mumps'            " filetype=mumps
 
  52 Plug 'kopischke/vim-fetch'            " handle opening filenames with line+column numbers
 
  53 Plug 'tpope/vim-scriptease'           " misc collection of helper commands
 
  54 Plug '~/.vim/bundle/airlinetheme-map' " override AirlineTheme for certain colorscheme's
 
  55 Plug '~/.vim/bundle/autofolds'        " folds for my *rc files
 
  60 if empty(glob('~/.vim/plugged'))
 
  61   autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
 
  64 " ----------------------------------------------------------------------------
 
  66 " ----------------------------------------------------------------------------
 
  69 let NERDTreeShowHidden=1              " show dotfiles by default
 
  70 let NERDTreeMinimalUI=1               " disable 'Press ? for help' text
 
  74 let g:ctrlp_show_hidden = 1
 
  75 let g:ctrlp_cache_dir = $HOME.'/.vim/.cache/ctrlp'
 
  76 let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
 
  79 let g:airline_mode_map = {
 
  92 if !exists('g:airline_symbols')
 
  93   let g:airline_symbols = {}
 
  96   let g:airline_powerline_fonts = 1   " use powerline font symbols
 
  98   let g:airline_symbols_ascii = 1     " use plain ascii symbols
 
  99   let g:airline_symbols.branch = 'BR:'
 
 101 let g:airline_symbols.linenr = ''
 
 102 let g:airline_symbols.maxlinenr = ''
 
 105 let g:gitgutter_enabled = 0           " disable by default
 
 108 let g:goyo_width = 80
 
 109 let g:limelight_conceal_ctermfg = 240
 
 110 let g:limelight_default_coefficient = 0.6
 
 111 let g:limelight_paragraph_span = 1    " show adjacent paragraphs
 
 112 let g:limelight_priority = -1         " don't overrule hlsearch
 
 114 function! s:goyo_enter()
 
 116     silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
 
 122 function! s:goyo_leave()
 
 124     silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
 
 130 autocmd! User GoyoEnter nested call <SID>goyo_enter()
 
 131 autocmd! User GoyoLeave nested call <SID>goyo_leave()
 
 134 let g:pandoc#syntax#conceal#use = 0   " disable conceal pretty display
 
 135 let g:pandoc#folding#fdc = 0          " disable foldcolumn
 
 136 let g:pandoc#folding#level = 6        " open all folds by default
 
 138 " ---------------------------------------------------------------------------
 
 140 " ---------------------------------------------------------------------------
 
 142 if !has("gui_running") && !(&term =~ '256color')
 
 143   if has("terminfo") && ! (&term == 'linux' || &term == 'Eterm' || &term == 'vt220' || &term == 'nsterm-16color' || &term == 'xterm-16color')
 
 144     " Force these terminals to accept my authority! (default)
 
 146     set t_AB=
\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm  " ANSI background
 
 147     set t_AF=
\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm  " ANSI foreground
 
 148   elseif &term == 'term' || &term == 'rxvt' || &term == 'vt100' || &term == 'screen'
 
 149     " Less-Cool Terminals (no terminfo)
 
 151     set t_AB=
\e[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
 
 152     set t_AF=
\e[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
 
 154     " Terminals that have trustworthy terminfo entries
 
 157       set t_Sf=
\e[3%dm  " foreground
 
 158       set t_Sb=
\e[4%dm  " background
 
 159     elseif $TERM == 'xterm'
 
 165 " ---------------------------------------------------------------------------
 
 167 " ---------------------------------------------------------------------------
 
 169 if &t_Co > 2 || has("gui_running")
 
 170   set background=dark                 " dark background
 
 171   syntax enable                       " syntax highligting
 
 173   " override colors in solarized colorscheme
 
 174   augroup vimrc_colorscheme_solarized
 
 176     if !has("gui_running")
 
 177       " override Normal ctermfg
 
 178       autocmd ColorScheme solarized highlight Normal ctermfg=None
 
 179       " override Comment ctermfg
 
 181         autocmd ColorScheme solarized highlight Comment ctermfg=241
 
 183         autocmd ColorScheme solarized highlight Comment ctermfg=DarkGrey
 
 185       " override visual block
 
 186       autocmd ColorScheme solarized highlight Visual term=reverse cterm=reverse ctermfg=DarkGreen ctermbg=White
 
 188         " override unprintable chars (listchars)
 
 189         autocmd ColorScheme solarized highlight SpecialKey ctermfg=DarkGrey ctermbg=Black
 
 194   " colorscheme theme options
 
 195   let g:solarized_termcolors=&t_Co    " use 256 colors for solarized
 
 196   let g:solarized_termtrans=1
 
 198   if !exists('s:set_colorscheme')
 
 199     colorscheme solarized
 
 200     let s:set_colorscheme=1
 
 203   " airline theme options
 
 204   let g:solarized16_termcolors=16     " always use 16 colors for 'solarized16' vim-airline theme
 
 205   let g:colorscheme_airlinetheme_map = {
 
 206         \ 'seoul256-light': 'zenburn',
 
 207         \ 'solarized': 'solarized16',
 
 209   let g:colorscheme_airlinetheme_default = 'distinguished'
 
 213 " ----------------------------------------------------------------------------
 
 215 " ----------------------------------------------------------------------------
 
 217 set nobackup                           " do not keep backups after close
 
 218 set nowritebackup                      " do not keep a backup while working
 
 219 set backupcopy=yes                     " keep attributes of original file
 
 220 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
 
 221 set directory=.,~/tmp,~/.vim/swap      " swap file directory-order
 
 222 set updatetime=1000                    " idle time before writing swap file to disk
 
 224 " ----------------------------------------------------------------------------
 
 226 " ----------------------------------------------------------------------------
 
 228 set ruler                  " show the cursor position all the time
 
 229 set showcmd                " display incomplete commands
 
 230 set nolazyredraw           " turn off lazy redraw
 
 231 set hidden                 " keep buffers loaded when hidden
 
 232 set showmode               " show mode at bottom of screen
 
 233 set wildmenu               " turn on wild menu
 
 234 set wildmode=list:longest,full
 
 235 set cmdheight=2            " command line height
 
 236 set backspace=2            " allow backspacing over everything in insert mode
 
 237 set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
 
 238 set shortmess=filtIoO      " shorten messages
 
 239 set report=0               " tell us about changes
 
 240 set nostartofline          " don't jump to the start of line when scrolling
 
 241 set scrolloff=4            " vertical padding
 
 242 set sidescroll=40          " side-scrolling increment (for nowrap mode)
 
 243 set sidescrolloff=10       " horz padding
 
 244 set tabpagemax=15          " open 15 tabs max
 
 245 set splitright             " put new vsplit windows to the right of the current
 
 247 " ----------------------------------------------------------------------------
 
 249 " ----------------------------------------------------------------------------
 
 251 set showmatch              " brackets/braces that is
 
 252 set matchtime=5            " duration to show matching brace (1/10 sec)
 
 253 set incsearch              " do incremental searching
 
 254 set laststatus=2           " always show the status line
 
 255 set ignorecase             " ignore case when searching
 
 256 set smartcase              " case-sensitive if search contains an uppercase character
 
 257 set visualbell             " shut the heck up
 
 258 set hlsearch               " highlight all search matches
 
 259 set list listchars=trail:·,tab:▸\ ,precedes:<,extends:>  " show trailing whitespace and tab chars
 
 261 " ----------------------------------------------------------------------------
 
 263 " ----------------------------------------------------------------------------
 
 265 if !exists(':AirlineTheme')
 
 266   set statusline=%1*\ %n%0*\ %<%f  " buffer #, filename
 
 267   set statusline+=\ %h%m%r   " file-state flags
 
 268   set statusline+=%=         " left-right divider
 
 269   set statusline+=%{strlen(&fenc)?&fenc:&enc},%{&ff}\ %y  " file-encoding, format, type
 
 270   set statusline+=\ %12.(%v,%l/%L%)\ \ %-4P  " cursor position, % through file of viewport
 
 273 " ----------------------------------------------------------------------------
 
 275 " ----------------------------------------------------------------------------
 
 277 set autoindent             " automatic indent new lines
 
 278 set smartindent            " be smart about it
 
 279 set nowrap                 " do not wrap lines
 
 280 set softtabstop=2          " yep, two
 
 281 set shiftwidth=2           " ..
 
 283 set expandtab              " expand tabs to spaces
 
 284 set smarttab               " smarter softtab handling
 
 285 set formatoptions+=n       " support for numbered/bullet lists
 
 286 set textwidth=0            " no line-wrapping by default
 
 287 set virtualedit=block      " allow virtual edit in visual block ..
 
 288 set spelllang=en_us        " spell-check dictionary
 
 290 " ----------------------------------------------------------------------------
 
 291 " Filename Exclusions
 
 292 " ----------------------------------------------------------------------------
 
 294 set wildignore+=.hg,.git,.svn         " version control directories
 
 295 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png  " image files
 
 296 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
 
 297 set wildignore+=*.pyc                 " Python byte code
 
 298 set wildignore+=*.sw?                 " Vim swap files
 
 299 set wildignore+=.DS_Store             " OSX junk
 
 301 " ----------------------------------------------------------------------------
 
 303 " ----------------------------------------------------------------------------
 
 305 " movement based on display lines not physical lines (sane movement with wrap turned on)
 
 314 inoremap <Down> <C-o>gj
 
 315 inoremap <Up> <C-o>gk
 
 316 " do not menu with left / right in command line
 
 317 cnoremap <Left> <Space><BS><Left>
 
 318 cnoremap <Right> <Space><BS><Right>
 
 320 " reflow paragraph with Q in normal and visual mode
 
 323 " remap U to <C-r> for easier redo
 
 325 " make Y consistent with C (c$) and D (d$)
 
 327 " disable default vim regex handling for searching
 
 330 " reselect visual block after indent/outdent
 
 334 " <Space> to turn off highlighting and clear any message already displayed.
 
 335 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
 
 337 " leader-based keyboard shortcuts
 
 340 nmap <leader>b :CtrlPBuffer<CR>
 
 341 nmap <leader>o :CtrlP<CR>
 
 342 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
 
 344 nmap <leader>d :NERDTreeToggle<CR>
 
 345 nmap <leader>f :NERDTreeFind<CR>
 
 347 nmap <leader>u :GundoToggle<CR>
 
 349 nmap <leader>gb :Gblame<CR>
 
 350 nmap <leader>gs :Gstatus<CR>
 
 351 nmap <leader>gd :Gdiff<CR>
 
 352 nmap <leader>gl :Glog<CR>
 
 353 nmap <leader>gc :Gcommit<CR>
 
 354 nmap <leader>gp :Gpush<CR>
 
 355 " cd to the directory containing the file in the buffer
 
 356 nmap <leader>cd :lcd %:h<CR>
 
 357 " toggle diffmode for a buffer
 
 358 function! DiffToggle()
 
 365 nmap <leader>df :call DiffToggle()<CR>
 
 366 " quickly edit/reload vimrc
 
 367 nmap <leader>ev :edit $MYVIMRC<CR>
 
 368 nmap <leader>sv :source $MYVIMRC<CR>
 
 369 " find merge conflict markers
 
 370 nmap <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
 
 372 nnoremap <leader>h1 m`yypVr=``
 
 373 nnoremap <leader>h2 m`yypVr-``
 
 374 nnoremap <leader>h3 m`^i### <esc>``4l
 
 375 nnoremap <leader>h4 m`^i#### <esc>``5l
 
 376 nnoremap <leader>h5 m`^i##### <esc>``6l
 
 378 nmap <leader>hls :set hlsearch! hlsearch?<CR>
 
 380 nmap <leader>wu mQviwU`Q
 
 381 nmap <leader>wl mQviwu`Q
 
 382 " upper/lower first char of word
 
 383 nmap <leader>wU mQgewvU`Q
 
 384 nmap <leader>wL mQgewvu`Q
 
 385 " smart paste - enable paste-mode and paste contents of system clipboard
 
 386 map <leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
 
 388 nmap <leader>sp :setlocal spell! spell?<CR>
 
 389 " set text wrapping toggles
 
 390 nmap <leader>tw :set wrap! wrap?<CR>
 
 391 " set list-whitespace-chars toggle
 
 392 nmap <leader>ws :set list! list?<CR>
 
 393 " open tag definition in a horz split
 
 394 nmap <leader>tag :split <CR>:exec("tag ".expand("<cword>"))<CR>
 
 396 nmap <leader>ht :GitGutterToggle<CR>
 
 397 nmap <leader>hp <Plug>GitGutterPreviewHunk
 
 398 nmap <leader>hu <Plug>GitGutterUndoHunk
 
 399 nmap <leader>hs <Plug>GitGutterStageHunk
 
 401 nnoremap <leader>G :Goyo<CR>
 
 403 " --------------------------------------------------------------------------
 
 405 " --------------------------------------------------------------------------
 
 408 " Run vim command, redirect output to a scratch buffer
 
 409 function! s:redir(cmd)
 
 417     setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified
 
 422 command! -nargs=+ -complete=command Redir call s:redir(<q-args>)
 
 425 " Make a scratch buffer with all of the leader keybindings.
 
 426 command! ListLeaders :call s:redir('nmap <leader>')
 
 429 " Use `git grep` to search for to-do comments, add matches to qflist
 
 430 function! s:todo() abort
 
 432   for cmd in ['git grep -nI -e TODO -e FIXME -e XXX 2> /dev/null',
 
 433             \ 'grep -rnI -e TODO -e FIXME -e XXX * 2> /dev/null']
 
 434     let lines = split(system(cmd), '\n')
 
 435     if v:shell_error != 0 | continue | endif
 
 437       let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3]
 
 438       call add(entries, { 'filename': fname, 'lnum': lno, 'text': text })
 
 444     call setqflist(entries)
 
 448 command! Todo call s:todo()
 
 450 " :StripTrailingWhitespace
 
 451 " Strip trailing whitespace
 
 452 function! StripTrailingWhitespace()
 
 453   " preparation: save last search, and cursor position.
 
 459   " clean up: restore previous search history, and cursor position
 
 463 command! StripTrailingWhitespace call StripTrailingWhitespace()
 
 465 " ---------------------------------------------------------------------------
 
 466 " Auto Commands / File Types
 
 467 " ---------------------------------------------------------------------------
 
 469 augroup vimrc_autocmds
 
 470   " clear auto command group so we don't define it multiple times
 
 472   " jump to last position of buffer when opening (but not for commit messages)
 
 473   au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$") |
 
 474                      \ exe "normal g'\"" | endif
 
 476   au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab
 
 479   au Filetype gitcommit set tw=68  spell
 
 480   " don't use cindent for javascript
 
 481   au FileType javascript setlocal nocindent
 
 482   " in Makefiles, use real tabs not tabs expanded to spaces
 
 483   au FileType make setlocal noexpandtab
 
 486 " --------------------------------------------------------------------------
 
 488 " --------------------------------------------------------------------------
 
 490 if filereadable(glob("~/.vimrc.local"))
 
 491   source ~/.vimrc.local
 
 494 " vim: foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum) foldtext=autofolds#foldtext() foldlevel=2