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 'mileszs/ack.vim' " Ack wrapper
51 Plug 'tpope/vim-fugitive' " Git wrappers
54 Plug 'tpope/vim-surround' " quoting/parenthesizing made simple
55 Plug 'tpope/vim-unimpaired' " pairs of handy bracket mappings
58 Plug 'tpope/vim-git' " filetype=gitcommit
59 Plug 'vim-pandoc/vim-pandoc'
60 Plug 'vim-pandoc/vim-pandoc-syntax' " filetype=markdown
61 Plug '~/.vim/bundle/mumps' " filetype=mumps
64 Plug 'kopischke/vim-fetch' " handle opening filenames with line+column numbers
65 Plug 'tpope/vim-scriptease' " misc collection of helper commands
66 Plug '~/.vim/bundle/airlinetheme-map' " override AirlineTheme for certain colorscheme's
67 Plug '~/.vim/bundle/autofolds' " folds for my *rc files
72 if empty(glob('~/.vim/plugged'))
73 autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
76 " ----------------------------------------------------------------------------
78 " ----------------------------------------------------------------------------
81 let NERDTreeShowHidden=1 " show dotfiles by default
82 let NERDTreeMinimalUI=1 " disable 'Press ? for help' text
86 let g:ctrlp_show_hidden = 1
87 let g:ctrlp_cache_dir = $HOME.'/.vim/.cache/ctrlp'
88 let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
91 let g:airline_mode_map = {
104 if !exists('g:airline_symbols')
105 let g:airline_symbols = {}
107 if has("gui_running")
108 let g:airline_powerline_fonts = 1 " use powerline font symbols
110 let g:airline_symbols_ascii = 1 " use plain ascii symbols
111 let g:airline_symbols.branch = 'BR:'
113 let g:airline_symbols.linenr = ''
114 let g:airline_symbols.maxlinenr = ''
117 let g:gitgutter_enabled = 0 " disable by default
120 let g:goyo_width = 80
121 let g:limelight_conceal_ctermfg = 240
122 let g:limelight_default_coefficient = 0.6
123 let g:limelight_paragraph_span = 1 " show adjacent paragraphs
124 let g:limelight_priority = -1 " don't overrule hlsearch
126 function! s:goyo_enter()
128 silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
134 function! s:goyo_leave()
136 silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
142 autocmd! User GoyoEnter nested call <SID>goyo_enter()
143 autocmd! User GoyoLeave nested call <SID>goyo_leave()
146 let g:pandoc#syntax#conceal#use = 0 " disable conceal pretty display
147 let g:pandoc#folding#fdc = 0 " disable foldcolumn
148 let g:pandoc#folding#level = 6 " open all folds by default
150 " ---------------------------------------------------------------------------
152 " ---------------------------------------------------------------------------
154 if !has("gui_running") && !(&term =~ '256color')
155 if has("terminfo") && ! (&term == 'linux' || &term == 'Eterm' || &term == 'vt220' || &term == 'nsterm-16color' || &term == 'xterm-16color')
156 " Force these terminals to accept my authority! (default)
158 set t_AB=
\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm " ANSI background
159 set t_AF=
\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm " ANSI foreground
160 elseif &term == 'term' || &term == 'rxvt' || &term == 'vt100' || &term == 'screen'
161 " Less-Cool Terminals (no terminfo)
163 set t_AB=
\e[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
164 set t_AF=
\e[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
166 " Terminals that have trustworthy terminfo entries
169 set t_Sf=
\e[3%dm " foreground
170 set t_Sb=
\e[4%dm " background
171 elseif $TERM == 'xterm'
177 " ---------------------------------------------------------------------------
179 " ---------------------------------------------------------------------------
181 if &t_Co > 2 || has("gui_running")
182 set background=dark " dark background
183 syntax enable " syntax highligting
185 " override colors in solarized colorscheme
186 augroup vimrc_colorscheme_solarized
188 if !has("gui_running")
189 " override Normal ctermfg
190 autocmd ColorScheme solarized highlight Normal ctermfg=None
191 " override Comment ctermfg
193 autocmd ColorScheme solarized highlight Comment ctermfg=241
195 autocmd ColorScheme solarized highlight Comment ctermfg=DarkGrey
197 " override visual block
198 autocmd ColorScheme solarized highlight Visual term=reverse cterm=reverse ctermfg=DarkGreen ctermbg=White
200 " override unprintable chars (listchars)
201 autocmd ColorScheme solarized highlight SpecialKey ctermfg=DarkGrey ctermbg=Black
206 " colorscheme theme options
207 let g:solarized_termcolors=&t_Co " use 256 colors for solarized
208 let g:solarized_termtrans=1
210 if !exists('s:set_colorscheme')
211 colorscheme solarized
212 let s:set_colorscheme=1
215 " airline theme options
216 let g:solarized16_termcolors=16 " always use 16 colors for 'solarized16' vim-airline theme
217 let g:colorscheme_airlinetheme_map = {
218 \ 'seoul256-light': 'zenburn',
219 \ 'solarized': 'solarized16',
221 let g:colorscheme_airlinetheme_default = 'distinguished'
225 " ----------------------------------------------------------------------------
227 " ----------------------------------------------------------------------------
229 set nobackup " do not keep backups after close
230 set nowritebackup " do not keep a backup while working
231 set backupcopy=yes " keep attributes of original file
232 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
233 set directory=.,~/tmp,~/.vim/swap " swap file directory-order
234 set updatetime=1000 " idle time before writing swap file to disk
236 " ----------------------------------------------------------------------------
238 " ----------------------------------------------------------------------------
240 set ruler " show the cursor position all the time
241 set showcmd " display incomplete commands
242 set nolazyredraw " turn off lazy redraw
243 set hidden " keep buffers loaded when hidden
244 set showmode " show mode at bottom of screen
245 set wildmenu " turn on wild menu
246 set wildmode=list:longest,full
247 set cmdheight=2 " command line height
248 set backspace=2 " allow backspacing over everything in insert mode
249 set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
250 set shortmess=filtIoO " shorten messages
251 set report=0 " tell us about changes
252 set nostartofline " don't jump to the start of line when scrolling
253 set scrolloff=4 " vertical padding
254 set sidescroll=40 " side-scrolling increment (for nowrap mode)
255 set sidescrolloff=10 " horz padding
256 set tabpagemax=15 " open 15 tabs max
257 set splitright " put new vsplit windows to the right of the current
259 " ----------------------------------------------------------------------------
261 " ----------------------------------------------------------------------------
263 set showmatch " brackets/braces that is
264 set matchtime=5 " duration to show matching brace (1/10 sec)
265 set incsearch " do incremental searching
266 set laststatus=2 " always show the status line
267 set ignorecase " ignore case when searching
268 set smartcase " case-sensitive if search contains an uppercase character
269 set visualbell " shut the heck up
270 set hlsearch " highlight all search matches
271 set list listchars=trail:·,tab:▸\ ,precedes:<,extends:> " show trailing whitespace and tab chars
273 " ----------------------------------------------------------------------------
275 " ----------------------------------------------------------------------------
277 if !exists(':AirlineTheme')
278 set statusline=%1*\ %n%0*\ %<%f " buffer #, filename
279 set statusline+=\ %h%m%r " file-state flags
280 set statusline+=%= " left-right divider
281 set statusline+=%{strlen(&fenc)?&fenc:&enc},%{&ff}\ %y " file-encoding, format, type
282 set statusline+=\ %12.(%v,%l/%L%)\ \ %-4P " cursor position, % through file of viewport
285 " ----------------------------------------------------------------------------
287 " ----------------------------------------------------------------------------
289 set autoindent " automatic indent new lines
290 set smartindent " be smart about it
291 set nowrap " do not wrap lines
292 set softtabstop=2 " yep, two
293 set shiftwidth=2 " ..
295 set expandtab " expand tabs to spaces
296 set smarttab " smarter softtab handling
297 set formatoptions+=n " support for numbered/bullet lists
298 set textwidth=0 " no line-wrapping by default
299 set virtualedit=block " allow virtual edit in visual block ..
300 set spelllang=en_us " spell-check dictionary
302 " ----------------------------------------------------------------------------
303 " Filename Exclusions
304 " ----------------------------------------------------------------------------
306 set wildignore+=.hg,.git,.svn " version control directories
307 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png " image files
308 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
309 set wildignore+=*.pyc " Python byte code
310 set wildignore+=*.sw? " Vim swap files
311 set wildignore+=.DS_Store " OSX junk
313 " ----------------------------------------------------------------------------
315 " ----------------------------------------------------------------------------
317 " movement based on display lines not physical lines (sane movement with wrap turned on)
326 inoremap <Down> <C-o>gj
327 inoremap <Up> <C-o>gk
328 " do not menu with left / right in command line
329 cnoremap <Left> <Space><BS><Left>
330 cnoremap <Right> <Space><BS><Right>
332 " reflow paragraph with Q in normal and visual mode
335 " remap U to <C-r> for easier redo
337 " make Y consistent with C (c$) and D (d$)
339 " disable default vim regex handling for searching
342 " reselect visual block after indent/outdent
346 " <Space> to turn off highlighting and clear any message already displayed.
347 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
349 " leader-based keyboard shortcuts
352 nmap <leader>b :CtrlPBuffer<CR>
353 nmap <leader>o :CtrlP<CR>
354 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
356 nmap <leader>d :NERDTreeToggle<CR>
357 nmap <leader>f :NERDTreeFind<CR>
359 nmap <leader>u :GundoToggle<CR>
361 nmap <leader>gb :Gblame<CR>
362 nmap <leader>gs :Gstatus<CR>
363 nmap <leader>gd :Gdiff<CR>
364 nmap <leader>gl :Glog<CR>
365 nmap <leader>gc :Gcommit<CR>
366 nmap <leader>gp :Gpush<CR>
367 " cd to the directory containing the file in the buffer
368 nmap <leader>cd :lcd %:h<CR>
369 " toggle diffmode for a buffer
370 function! DiffToggle()
377 nmap <leader>df :call DiffToggle()<CR>
378 " quickly edit/reload vimrc
379 nmap <leader>ev :edit $MYVIMRC<CR>
380 nmap <leader>sv :source $MYVIMRC<CR>
381 " find merge conflict markers
382 nmap <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
384 nnoremap <leader>h1 m`yypVr=``
385 nnoremap <leader>h2 m`yypVr-``
386 nnoremap <leader>h3 m`^i### <esc>``4l
387 nnoremap <leader>h4 m`^i#### <esc>``5l
388 nnoremap <leader>h5 m`^i##### <esc>``6l
390 nmap <leader>hls :set hlsearch! hlsearch?<CR>
392 nmap <leader>wu mQviwU`Q
393 nmap <leader>wl mQviwu`Q
394 " upper/lower first char of word
395 nmap <leader>wU mQgewvU`Q
396 nmap <leader>wL mQgewvu`Q
397 " smart paste - enable paste-mode and paste contents of system clipboard
398 map <leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
400 nmap <leader>sp :setlocal spell! spell?<CR>
401 " set text wrapping toggles
402 nmap <leader>tw :set wrap! wrap?<CR>
403 " set list-whitespace-chars toggle
404 nmap <leader>ws :set list! list?<CR>
405 " open tag definition in a horz split
406 nmap <leader>tag :split <CR>:exec("tag ".expand("<cword>"))<CR>
408 nmap <leader>ht :GitGutterToggle<CR>
409 nmap <leader>hp <Plug>GitGutterPreviewHunk
410 nmap <leader>hu <Plug>GitGutterUndoHunk
411 nmap <leader>hs <Plug>GitGutterStageHunk
413 nnoremap <leader>G :Goyo<CR>
415 " --------------------------------------------------------------------------
417 " --------------------------------------------------------------------------
420 " Run vim command, redirect output to a scratch buffer
421 function! s:redir(cmd)
429 setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified
434 command! -nargs=+ -complete=command Redir call s:redir(<q-args>)
437 " Make a scratch buffer with all of the leader keybindings.
438 command! ListLeaders :call s:redir('nmap <leader>')
441 " Use `git grep` to search for to-do comments, add matches to qflist
442 function! s:todo() abort
444 for cmd in ['git grep -nI -e TODO -e FIXME -e XXX 2> /dev/null',
445 \ 'grep -rnI -e TODO -e FIXME -e XXX * 2> /dev/null']
446 let lines = split(system(cmd), '\n')
447 if v:shell_error != 0 | continue | endif
449 let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3]
450 call add(entries, { 'filename': fname, 'lnum': lno, 'text': text })
456 call setqflist(entries)
460 command! Todo call s:todo()
462 " :StripTrailingWhitespace
463 " Strip trailing whitespace
464 function! StripTrailingWhitespace()
465 " preparation: save last search, and cursor position.
471 " clean up: restore previous search history, and cursor position
475 command! StripTrailingWhitespace call StripTrailingWhitespace()
477 " ---------------------------------------------------------------------------
478 " Auto Commands / File Types
479 " ---------------------------------------------------------------------------
481 " override Filetype settings
482 augroup vimrc_filetype
485 au Filetype sh,bash setlocal ts=4 sts=4 sw=4 expandtab
487 " git commit message: enable spell checking
488 au Filetype gitcommit setlocal spell
489 " gitconfig file: use real tabs
490 au Filetype gitconfig setlocal noexpandtab
491 " javascript: don't use cindent
492 au FileType javascript setlocal nocindent
493 " makefiles: use real tabs
494 au FileType make setlocal noexpandtab
497 " --------------------------------------------------------------------------
499 " --------------------------------------------------------------------------
501 if filereadable(glob("~/.vimrc.local"))
502 source ~/.vimrc.local
505 " vim: foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum) foldtext=autofolds#foldtext() foldlevel=2