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/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 = 'BR:'
100 let g:airline_symbols.linenr = ''
101 let g:airline_symbols.maxlinenr = ''
104 let g:gitgutter_enabled = 0 " disable by default
107 let g:goyo_width = 80
108 let g:limelight_conceal_ctermfg = 240
109 let g:limelight_default_coefficient = 0.6
110 let g:limelight_paragraph_span = 1 " show adjacent paragraphs
111 let g:limelight_priority = -1 " don't overrule hlsearch
113 function! s:goyo_enter()
115 silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
121 function! s:goyo_leave()
123 silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
129 autocmd! User GoyoEnter nested call <SID>goyo_enter()
130 autocmd! User GoyoLeave nested call <SID>goyo_leave()
133 let g:pandoc#syntax#conceal#use = 0 " disable conceal pretty display
134 let g:pandoc#folding#fdc = 0 " disable foldcolumn
135 let g:pandoc#folding#level = 6 " open all folds by default
137 " ---------------------------------------------------------------------------
139 " ---------------------------------------------------------------------------
141 if !has("gui_running") && !(&term =~ '256color')
142 if has("terminfo") && ! (&term == 'linux' || &term == 'Eterm' || &term == 'vt220' || &term == 'nsterm-16color' || &term == 'xterm-16color')
143 " Force these terminals to accept my authority! (default)
145 set t_AB=
\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm " ANSI background
146 set t_AF=
\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm " ANSI foreground
147 elseif &term == 'term' || &term == 'rxvt' || &term == 'vt100' || &term == 'screen'
148 " Less-Cool Terminals (no terminfo)
150 set t_AB=
\e[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
151 set t_AF=
\e[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
153 " Terminals that have trustworthy terminfo entries
156 set t_Sf=
\e[3%dm " foreground
157 set t_Sb=
\e[4%dm " background
158 elseif $TERM == 'xterm'
164 " ---------------------------------------------------------------------------
166 " ---------------------------------------------------------------------------
168 if &t_Co > 2 || has("gui_running")
169 set background=dark " dark background
170 syntax enable " syntax highligting
172 " override colors in solarized colorscheme
173 augroup vimrc_colorscheme_solarized
175 if !has("gui_running")
176 " override Normal ctermfg
177 autocmd ColorScheme solarized highlight Normal ctermfg=None
178 " override Comment ctermfg
180 autocmd ColorScheme solarized highlight Comment ctermfg=241
182 autocmd ColorScheme solarized highlight Comment ctermfg=DarkGrey
184 " override visual block
185 autocmd ColorScheme solarized highlight Visual term=reverse cterm=reverse ctermfg=DarkGreen ctermbg=White
187 " override unprintable chars (listchars)
188 autocmd ColorScheme solarized highlight SpecialKey ctermfg=DarkGrey ctermbg=Black
193 let g:solarized_termcolors=&t_Co " use 256 colors for solarized
194 let g:solarized_termtrans=1
195 colorscheme solarized
197 let g:airline_theme='solarized16' " vim-airline theme
198 let g:solarized16_termcolors=16 " always use 16 colors for 'solarized16' vim-airline theme
201 " ----------------------------------------------------------------------------
203 " ----------------------------------------------------------------------------
205 set nobackup " do not keep backups after close
206 set nowritebackup " do not keep a backup while working
207 set backupcopy=yes " keep attributes of original file
208 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
209 set directory=.,~/tmp,~/.vim/swap " swap file directory-order
210 set updatetime=1000 " idle time before writing swap file to disk
212 " ----------------------------------------------------------------------------
214 " ----------------------------------------------------------------------------
216 set ruler " show the cursor position all the time
217 set showcmd " display incomplete commands
218 set nolazyredraw " turn off lazy redraw
219 set hidden " keep buffers loaded when hidden
220 set showmode " show mode at bottom of screen
221 set wildmenu " turn on wild menu
222 set wildmode=list:longest,full
223 set cmdheight=2 " command line height
224 set backspace=2 " allow backspacing over everything in insert mode
225 set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
226 set shortmess=filtIoO " shorten messages
227 set report=0 " tell us about changes
228 set nostartofline " don't jump to the start of line when scrolling
229 set scrolloff=4 " vertical padding
230 set sidescroll=40 " side-scrolling increment (for nowrap mode)
231 set sidescrolloff=10 " horz padding
232 set tabpagemax=15 " open 15 tabs max
233 set splitright " put new vsplit windows to the right of the current
235 " ----------------------------------------------------------------------------
237 " ----------------------------------------------------------------------------
239 set showmatch " brackets/braces that is
240 set matchtime=5 " duration to show matching brace (1/10 sec)
241 set incsearch " do incremental searching
242 set laststatus=2 " always show the status line
243 set ignorecase " ignore case when searching
244 set smartcase " case-sensitive if search contains an uppercase character
245 set visualbell " shut the heck up
246 set hlsearch " highlight all search matches
247 set list listchars=trail:·,tab:▸\ ,precedes:<,extends:> " show trailing whitespace and tab chars
249 " ----------------------------------------------------------------------------
251 " ----------------------------------------------------------------------------
253 if !exists(':AirlineTheme')
254 set statusline=%1*\ %n%0*\ %<%f " buffer #, filename
255 set statusline+=\ %h%m%r " file-state flags
256 set statusline+=%= " left-right divider
257 set statusline+=%{strlen(&fenc)?&fenc:&enc},%{&ff}\ %y " file-encoding, format, type
258 set statusline+=\ %12.(%v,%l/%L%)\ \ %-4P " cursor position, % through file of viewport
261 " ----------------------------------------------------------------------------
263 " ----------------------------------------------------------------------------
265 set autoindent " automatic indent new lines
266 set smartindent " be smart about it
267 set nowrap " do not wrap lines
268 set softtabstop=2 " yep, two
269 set shiftwidth=2 " ..
271 set expandtab " expand tabs to spaces
272 set smarttab " smarter softtab handling
273 set formatoptions+=n " support for numbered/bullet lists
274 set textwidth=0 " no line-wrapping by default
275 set virtualedit=block " allow virtual edit in visual block ..
276 set spelllang=en_us " spell-check dictionary
278 " ----------------------------------------------------------------------------
279 " Filename Exclusions
280 " ----------------------------------------------------------------------------
282 set wildignore+=.hg,.git,.svn " version control directories
283 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png " image files
284 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
285 set wildignore+=*.pyc " Python byte code
286 set wildignore+=*.sw? " Vim swap files
287 set wildignore+=.DS_Store " OSX junk
289 " ----------------------------------------------------------------------------
291 " ----------------------------------------------------------------------------
293 " movement based on display lines not physical lines (sane movement with wrap turned on)
302 inoremap <Down> <C-o>gj
303 inoremap <Up> <C-o>gk
304 " do not menu with left / right in command line
305 cnoremap <Left> <Space><BS><Left>
306 cnoremap <Right> <Space><BS><Right>
308 " reflow paragraph with Q in normal and visual mode
311 " remap U to <C-r> for easier redo
313 " make Y consistent with C (c$) and D (d$)
315 " disable default vim regex handling for searching
318 " reselect visual block after indent/outdent
322 " <Space> to turn off highlighting and clear any message already displayed.
323 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
325 " leader-based keyboard shortcuts
328 nmap <leader>b :CtrlPBuffer<CR>
329 nmap <leader>o :CtrlP<CR>
330 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
332 nmap <leader>d :NERDTreeToggle<CR>
333 nmap <leader>f :NERDTreeFind<CR>
335 nmap <leader>u :GundoToggle<CR>
337 nmap <leader>gb :Gblame<CR>
338 nmap <leader>gs :Gstatus<CR>
339 nmap <leader>gd :Gdiff<CR>
340 nmap <leader>gl :Glog<CR>
341 nmap <leader>gc :Gcommit<CR>
342 nmap <leader>gp :Gpush<CR>
343 " cd to the directory containing the file in the buffer
344 nmap <leader>cd :lcd %:h<CR>
345 " toggle diffmode for a buffer
346 function! DiffToggle()
353 nmap <leader>df :call DiffToggle()<CR>
354 " quickly edit/reload vimrc
355 nmap <leader>ev :edit $MYVIMRC<CR>
356 nmap <leader>sv :source $MYVIMRC<CR>
357 " find merge conflict markers
358 nmap <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
360 nnoremap <leader>h1 m`yypVr=``
361 nnoremap <leader>h2 m`yypVr-``
362 nnoremap <leader>h3 m`^i### <esc>``4l
363 nnoremap <leader>h4 m`^i#### <esc>``5l
364 nnoremap <leader>h5 m`^i##### <esc>``6l
366 nmap <leader>hls :set hlsearch! hlsearch?<CR>
368 nmap <leader>wu mQviwU`Q
369 nmap <leader>wl mQviwu`Q
370 " upper/lower first char of word
371 nmap <leader>wU mQgewvU`Q
372 nmap <leader>wL mQgewvu`Q
373 " smart paste - enable paste-mode and paste contents of system clipboard
374 map <leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
376 nmap <leader>r :redraw!<CR>
378 nmap <leader>sp :setlocal spell! spell?<CR>
379 " set text wrapping toggles
380 nmap <leader>tw :set wrap! wrap?<CR>
381 " set list-whitespace-chars toggle
382 nmap <leader>ws :set list! list?<CR>
383 " open tag definition in a horz split
384 nmap <leader>tag :split <CR>:exec("tag ".expand("<cword>"))<CR>
386 nmap <leader>ht :GitGutterToggle<CR>
387 nmap <leader>hp <Plug>GitGutterPreviewHunk
388 nmap <leader>hu <Plug>GitGutterUndoHunk
389 nmap <leader>hs <Plug>GitGutterStageHunk
391 nnoremap <leader>G :Goyo<CR>
393 " --------------------------------------------------------------------------
395 " --------------------------------------------------------------------------
398 " Run vim command, redirect output to a scratch buffer
399 function! s:redir(cmd)
407 setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified
412 command! -nargs=+ -complete=command Redir call s:redir(<q-args>)
415 " Make a scratch buffer with all of the leader keybindings.
416 command! ListLeaders :call s:redir('nmap <leader>')
419 " Use `git grep` to search for to-do comments, add matches to qflist
420 function! s:todo() abort
422 for cmd in ['git grep -nI -e TODO -e FIXME -e XXX 2> /dev/null',
423 \ 'grep -rnI -e TODO -e FIXME -e XXX * 2> /dev/null']
424 let lines = split(system(cmd), '\n')
425 if v:shell_error != 0 | continue | endif
427 let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3]
428 call add(entries, { 'filename': fname, 'lnum': lno, 'text': text })
434 call setqflist(entries)
438 command! Todo call s:todo()
440 " :StripTrailingWhitespace
441 " Strip trailing whitespace
442 function! StripTrailingWhitespace()
443 " preparation: save last search, and cursor position.
449 " clean up: restore previous search history, and cursor position
453 command! StripTrailingWhitespace call StripTrailingWhitespace()
455 " ---------------------------------------------------------------------------
456 " Auto Commands / File Types
457 " ---------------------------------------------------------------------------
459 augroup vimrc_autocmds
460 " clear auto command group so we don't define it multiple times
462 " jump to last position of buffer when opening (but not for commit messages)
463 au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$") |
464 \ exe "normal g'\"" | endif
466 au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab
469 au Filetype gitcommit set tw=68 spell
470 " don't use cindent for javascript
471 au FileType javascript setlocal nocindent
472 " in Makefiles, use real tabs not tabs expanded to spaces
473 au FileType make setlocal noexpandtab
476 " --------------------------------------------------------------------------
478 " --------------------------------------------------------------------------
480 if filereadable(glob("~/.vimrc.local"))
481 source ~/.vimrc.local
484 " vim: foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum) foldtext=autofolds#foldtext() foldlevel=2