]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - .vimrc
.vimrc: Add more colorschemes
[dotfiles.git] / .vimrc
1 " ---------------------------------------------------------------------------
2 " General
3 " ---------------------------------------------------------------------------
4
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)
13
14 " ---------------------------------------------------------------------------
15 " Plugins
16 " ---------------------------------------------------------------------------
17
18 call plug#begin('~/.vim/plugged')
19
20 " Colors
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'
36
37 " Interface
38 Plug 'airblade/vim-gitgutter' " shows git diff in the gutter
39 Plug 'godlygeek/csapprox' " make gui-only colorschemes work automagically in terminal vim
40 Plug 'junegunn/goyo.vim' " distraction-free writing
41 Plug 'junegunn/limelight.vim' " hyperfocus-writing
42 Plug 'kien/ctrlp.vim' " fuzzy file, buffer, mru, etc finder
43 Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " file system explorer
44 Plug 'sjl/gundo.vim' " visualize undo tree
45 Plug 'vim-airline/vim-airline' " lean & mean status/tabline
46 Plug 'vim-airline/vim-airline-themes' " themes for vim-airline
47
48 " Integrations
49 Plug 'mileszs/ack.vim' " Ack wrapper
50 Plug 'tpope/vim-fugitive' " Git wrappers
51
52 " Edit
53 Plug 'tpope/vim-surround' " quoting/parenthesizing made simple
54 Plug 'tpope/vim-unimpaired' " pairs of handy bracket mappings
55
56 " Language / Syntax
57 Plug 'tpope/vim-git' " filetype=gitcommit
58 Plug 'vim-pandoc/vim-pandoc'
59 Plug 'vim-pandoc/vim-pandoc-syntax' " filetype=markdown
60 Plug '~/.vim/bundle/mumps' " filetype=mumps
61
62 " Other
63 Plug 'kopischke/vim-fetch' " handle opening filenames with line+column numbers
64 Plug 'tpope/vim-scriptease' " misc collection of helper commands
65 Plug '~/.vim/bundle/airlinetheme-map' " override AirlineTheme for certain colorscheme's
66 Plug '~/.vim/bundle/autofolds' " folds for my *rc files
67
68 call plug#end()
69
70 " Automatic install
71 if empty(glob('~/.vim/plugged'))
72 autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
73 endif
74
75 " ----------------------------------------------------------------------------
76 " Plugin Settings
77 " ----------------------------------------------------------------------------
78
79 " NERDTree
80 let NERDTreeShowHidden=1 " show dotfiles by default
81 let NERDTreeMinimalUI=1 " disable 'Press ? for help' text
82
83 " Ctrl-P
84 let g:ctrlp_map = ''
85 let g:ctrlp_show_hidden = 1
86 let g:ctrlp_cache_dir = $HOME.'/.vim/.cache/ctrlp'
87 let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
88
89 " Airline
90 let g:airline_mode_map = {
91 \ '__' : '-',
92 \ 'n' : 'N',
93 \ 'i' : 'I',
94 \ 'R' : 'R',
95 \ 'c' : 'C',
96 \ 'v' : 'V',
97 \ 'V' : 'V',
98 \ '\16' : 'V',
99 \ 's' : 'S',
100 \ 'S' : 'S',
101 \ '\13' : 'S',
102 \ }
103 if !exists('g:airline_symbols')
104 let g:airline_symbols = {}
105 endif
106 if has("gui_running")
107 let g:airline_powerline_fonts = 1 " use powerline font symbols
108 else
109 let g:airline_symbols_ascii = 1 " use plain ascii symbols
110 let g:airline_symbols.branch = 'BR:'
111 endif
112 let g:airline_symbols.linenr = ''
113 let g:airline_symbols.maxlinenr = ''
114
115 " gitgutter
116 let g:gitgutter_enabled = 0 " disable by default
117
118 " goyo + limelight
119 let g:goyo_width = 80
120 let g:limelight_conceal_ctermfg = 240
121 let g:limelight_default_coefficient = 0.6
122 let g:limelight_paragraph_span = 1 " show adjacent paragraphs
123 let g:limelight_priority = -1 " don't overrule hlsearch
124
125 function! s:goyo_enter()
126 if exists('$TMUX')
127 silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
128 endif
129 set scrolloff=999
130 Limelight
131 endfunction
132
133 function! s:goyo_leave()
134 if exists('$TMUX')
135 silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
136 endif
137 set scrolloff=4
138 Limelight!
139 endfunction
140
141 autocmd! User GoyoEnter nested call <SID>goyo_enter()
142 autocmd! User GoyoLeave nested call <SID>goyo_leave()
143
144 " vim-pandoc
145 let g:pandoc#syntax#conceal#use = 0 " disable conceal pretty display
146 let g:pandoc#folding#fdc = 0 " disable foldcolumn
147 let g:pandoc#folding#level = 6 " open all folds by default
148
149 " ---------------------------------------------------------------------------
150 " Terminal Settings
151 " ---------------------------------------------------------------------------
152
153 if !has("gui_running") && !(&term =~ '256color')
154 if has("terminfo") && ! (&term == 'linux' || &term == 'Eterm' || &term == 'vt220' || &term == 'nsterm-16color' || &term == 'xterm-16color')
155 " Force these terminals to accept my authority! (default)
156 set t_Co=16
157 set t_AB=\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm " ANSI background
158 set t_AF=\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm " ANSI foreground
159 elseif &term == 'term' || &term == 'rxvt' || &term == 'vt100' || &term == 'screen'
160 " Less-Cool Terminals (no terminfo)
161 set t_Co=16
162 set t_AB=\e[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
163 set t_AF=\e[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
164 else
165 " Terminals that have trustworthy terminfo entries
166 if &term == 'vt220'
167 set t_Co=8
168 set t_Sf=\e[3%dm " foreground
169 set t_Sb=\e[4%dm " background
170 elseif $TERM == 'xterm'
171 set term=xterm-color
172 endif
173 endif
174 endif
175
176 " ---------------------------------------------------------------------------
177 " Colors / Theme
178 " ---------------------------------------------------------------------------
179
180 if &t_Co > 2 || has("gui_running")
181 set background=dark " dark background
182 syntax enable " syntax highligting
183
184 " override colors in solarized colorscheme
185 augroup vimrc_colorscheme_solarized
186 autocmd!
187 if !has("gui_running")
188 " override Normal ctermfg
189 autocmd ColorScheme solarized highlight Normal ctermfg=None
190 " override Comment ctermfg
191 if &t_Co == 256
192 autocmd ColorScheme solarized highlight Comment ctermfg=241
193 else
194 autocmd ColorScheme solarized highlight Comment ctermfg=DarkGrey
195 endif
196 " override visual block
197 autocmd ColorScheme solarized highlight Visual term=reverse cterm=reverse ctermfg=DarkGreen ctermbg=White
198 if &t_Co < 256
199 " override unprintable chars (listchars)
200 autocmd ColorScheme solarized highlight SpecialKey ctermfg=DarkGrey ctermbg=Black
201 endif
202 endif
203 augroup END
204
205 " colorscheme theme options
206 let g:solarized_termcolors=&t_Co " use 256 colors for solarized
207 let g:solarized_termtrans=1
208
209 if !exists('s:set_colorscheme')
210 colorscheme solarized
211 let s:set_colorscheme=1
212 endif
213
214 " airline theme options
215 let g:solarized16_termcolors=16 " always use 16 colors for 'solarized16' vim-airline theme
216 let g:colorscheme_airlinetheme_map = {
217 \ 'seoul256-light': 'zenburn',
218 \ 'solarized': 'solarized16',
219 \ }
220 let g:colorscheme_airlinetheme_default = 'distinguished'
221
222 endif
223
224 " ----------------------------------------------------------------------------
225 " Backups
226 " ----------------------------------------------------------------------------
227
228 set nobackup " do not keep backups after close
229 set nowritebackup " do not keep a backup while working
230 set backupcopy=yes " keep attributes of original file
231 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
232 set directory=.,~/tmp,~/.vim/swap " swap file directory-order
233 set updatetime=1000 " idle time before writing swap file to disk
234
235 " ----------------------------------------------------------------------------
236 " UI
237 " ----------------------------------------------------------------------------
238
239 set ruler " show the cursor position all the time
240 set showcmd " display incomplete commands
241 set nolazyredraw " turn off lazy redraw
242 set hidden " keep buffers loaded when hidden
243 set showmode " show mode at bottom of screen
244 set wildmenu " turn on wild menu
245 set wildmode=list:longest,full
246 set cmdheight=2 " command line height
247 set backspace=2 " allow backspacing over everything in insert mode
248 set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
249 set shortmess=filtIoO " shorten messages
250 set report=0 " tell us about changes
251 set nostartofline " don't jump to the start of line when scrolling
252 set scrolloff=4 " vertical padding
253 set sidescroll=40 " side-scrolling increment (for nowrap mode)
254 set sidescrolloff=10 " horz padding
255 set tabpagemax=15 " open 15 tabs max
256 set splitright " put new vsplit windows to the right of the current
257
258 " ----------------------------------------------------------------------------
259 " Visual Cues
260 " ----------------------------------------------------------------------------
261
262 set showmatch " brackets/braces that is
263 set matchtime=5 " duration to show matching brace (1/10 sec)
264 set incsearch " do incremental searching
265 set laststatus=2 " always show the status line
266 set ignorecase " ignore case when searching
267 set smartcase " case-sensitive if search contains an uppercase character
268 set visualbell " shut the heck up
269 set hlsearch " highlight all search matches
270 set list listchars=trail:·,tab:▸\ ,precedes:<,extends:> " show trailing whitespace and tab chars
271
272 " ----------------------------------------------------------------------------
273 " Status Line
274 " ----------------------------------------------------------------------------
275
276 if !exists(':AirlineTheme')
277 set statusline=%1*\ %n%0*\ %<%f " buffer #, filename
278 set statusline+=\ %h%m%r " file-state flags
279 set statusline+=%= " left-right divider
280 set statusline+=%{strlen(&fenc)?&fenc:&enc},%{&ff}\ %y " file-encoding, format, type
281 set statusline+=\ %12.(%v,%l/%L%)\ \ %-4P " cursor position, % through file of viewport
282 endif
283
284 " ----------------------------------------------------------------------------
285 " Text Formatting
286 " ----------------------------------------------------------------------------
287
288 set autoindent " automatic indent new lines
289 set smartindent " be smart about it
290 set nowrap " do not wrap lines
291 set softtabstop=2 " yep, two
292 set shiftwidth=2 " ..
293 set tabstop=4
294 set expandtab " expand tabs to spaces
295 set smarttab " smarter softtab handling
296 set formatoptions+=n " support for numbered/bullet lists
297 set textwidth=0 " no line-wrapping by default
298 set virtualedit=block " allow virtual edit in visual block ..
299 set spelllang=en_us " spell-check dictionary
300
301 " ----------------------------------------------------------------------------
302 " Filename Exclusions
303 " ----------------------------------------------------------------------------
304
305 set wildignore+=.hg,.git,.svn " version control directories
306 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png " image files
307 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
308 set wildignore+=*.pyc " Python byte code
309 set wildignore+=*.sw? " Vim swap files
310 set wildignore+=.DS_Store " OSX junk
311
312 " ----------------------------------------------------------------------------
313 " Key Mappings
314 " ----------------------------------------------------------------------------
315
316 " movement based on display lines not physical lines (sane movement with wrap turned on)
317 nnoremap j gj
318 nnoremap k gk
319 vnoremap j gj
320 vnoremap k gk
321 nnoremap <Down> gj
322 nnoremap <Up> gk
323 vnoremap <Down> gj
324 vnoremap <Up> gk
325 inoremap <Down> <C-o>gj
326 inoremap <Up> <C-o>gk
327 " do not menu with left / right in command line
328 cnoremap <Left> <Space><BS><Left>
329 cnoremap <Right> <Space><BS><Right>
330
331 " reflow paragraph with Q in normal and visual mode
332 nnoremap Q gqap
333 vnoremap Q gq
334 " remap U to <C-r> for easier redo
335 nnoremap U <C-r>
336 " make Y consistent with C (c$) and D (d$)
337 nnoremap Y y$
338 " disable default vim regex handling for searching
339 nnoremap / /\v
340 vnoremap / /\v
341 " reselect visual block after indent/outdent
342 vnoremap < <gv
343 vnoremap > >gv
344
345 " <Space> to turn off highlighting and clear any message already displayed.
346 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
347
348 " leader-based keyboard shortcuts
349 let mapleader = ","
350 " CtrlP
351 nmap <leader>b :CtrlPBuffer<CR>
352 nmap <leader>o :CtrlP<CR>
353 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
354 " NERDTree
355 nmap <leader>d :NERDTreeToggle<CR>
356 nmap <leader>f :NERDTreeFind<CR>
357 " Gundo
358 nmap <leader>u :GundoToggle<CR>
359 " Fugitive (Git)
360 nmap <leader>gb :Gblame<CR>
361 nmap <leader>gs :Gstatus<CR>
362 nmap <leader>gd :Gdiff<CR>
363 nmap <leader>gl :Glog<CR>
364 nmap <leader>gc :Gcommit<CR>
365 nmap <leader>gp :Gpush<CR>
366 " cd to the directory containing the file in the buffer
367 nmap <leader>cd :lcd %:h<CR>
368 " toggle diffmode for a buffer
369 function! DiffToggle()
370 if &diff
371 diffoff
372 else
373 diffthis
374 endif
375 endfunction
376 nmap <leader>df :call DiffToggle()<CR>
377 " quickly edit/reload vimrc
378 nmap <leader>ev :edit $MYVIMRC<CR>
379 nmap <leader>sv :source $MYVIMRC<CR>
380 " find merge conflict markers
381 nmap <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
382 " markdown headings
383 nnoremap <leader>h1 m`yypVr=``
384 nnoremap <leader>h2 m`yypVr-``
385 nnoremap <leader>h3 m`^i### <esc>``4l
386 nnoremap <leader>h4 m`^i#### <esc>``5l
387 nnoremap <leader>h5 m`^i##### <esc>``6l
388 " toggle hlsearch
389 nmap <leader>hls :set hlsearch! hlsearch?<CR>
390 " upper/lower word
391 nmap <leader>wu mQviwU`Q
392 nmap <leader>wl mQviwu`Q
393 " upper/lower first char of word
394 nmap <leader>wU mQgewvU`Q
395 nmap <leader>wL mQgewvu`Q
396 " smart paste - enable paste-mode and paste contents of system clipboard
397 map <leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
398 " toggle spell-check
399 nmap <leader>sp :setlocal spell! spell?<CR>
400 " set text wrapping toggles
401 nmap <leader>tw :set wrap! wrap?<CR>
402 " set list-whitespace-chars toggle
403 nmap <leader>ws :set list! list?<CR>
404 " open tag definition in a horz split
405 nmap <leader>tag :split <CR>:exec("tag ".expand("<cword>"))<CR>
406 " gitgutter
407 nmap <leader>ht :GitGutterToggle<CR>
408 nmap <leader>hp <Plug>GitGutterPreviewHunk
409 nmap <leader>hu <Plug>GitGutterUndoHunk
410 nmap <leader>hs <Plug>GitGutterStageHunk
411 " goyo
412 nnoremap <leader>G :Goyo<CR>
413
414 " --------------------------------------------------------------------------
415 " Functions
416 " --------------------------------------------------------------------------
417
418 " :Redir
419 " Run vim command, redirect output to a scratch buffer
420 function! s:redir(cmd)
421 redir => message
422 silent execute a:cmd
423 redir END
424 if empty(message)
425 echoerr "no output"
426 else
427 new
428 setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified
429 silent! put=message
430 silent! g/^s*$/d
431 endif
432 endfunction
433 command! -nargs=+ -complete=command Redir call s:redir(<q-args>)
434
435 " :ListLeaders
436 " Make a scratch buffer with all of the leader keybindings.
437 command! ListLeaders :call s:redir('nmap <leader>')
438
439 " :Todo
440 " Use `git grep` to search for to-do comments, add matches to qflist
441 function! s:todo() abort
442 let entries = []
443 for cmd in ['git grep -nI -e TODO -e FIXME -e XXX 2> /dev/null',
444 \ 'grep -rnI -e TODO -e FIXME -e XXX * 2> /dev/null']
445 let lines = split(system(cmd), '\n')
446 if v:shell_error != 0 | continue | endif
447 for line in lines
448 let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3]
449 call add(entries, { 'filename': fname, 'lnum': lno, 'text': text })
450 endfor
451 break
452 endfor
453
454 if !empty(entries)
455 call setqflist(entries)
456 copen
457 endif
458 endfunction
459 command! Todo call s:todo()
460
461 " :StripTrailingWhitespace
462 " Strip trailing whitespace
463 function! StripTrailingWhitespace()
464 " preparation: save last search, and cursor position.
465 let _s=@/
466 let l = line(".")
467 let c = col(".")
468 " do the business
469 %s/\s\+$//e
470 " clean up: restore previous search history, and cursor position
471 let @/=_s
472 call cursor(l, c)
473 endfunction
474 command! StripTrailingWhitespace call StripTrailingWhitespace()
475
476 " ---------------------------------------------------------------------------
477 " Auto Commands / File Types
478 " ---------------------------------------------------------------------------
479
480 augroup vimrc_autocmds
481 " clear auto command group so we don't define it multiple times
482 autocmd!
483 " jump to last position of buffer when opening (but not for commit messages)
484 au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$") |
485 \ exe "normal g'\"" | endif
486 " sh config
487 au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab
488 let g:is_bash = 1
489 " git commit message
490 au Filetype gitcommit set tw=68 spell
491 " don't use cindent for javascript
492 au FileType javascript setlocal nocindent
493 " in Makefiles, use real tabs not tabs expanded to spaces
494 au FileType make setlocal noexpandtab
495 augroup END
496
497 " --------------------------------------------------------------------------
498 " Local Settings
499 " --------------------------------------------------------------------------
500
501 if filereadable(glob("~/.vimrc.local"))
502 source ~/.vimrc.local
503 endif
504
505 " vim: foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum) foldtext=autofolds#foldtext() foldlevel=2