]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - .vimrc
.vimrc: Use `highlight Todo` to highlight to-do comments
[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 Plug 'altercation/vim-colors-solarized'
20 Plug 'kien/ctrlp.vim'
21 Plug 'kopischke/vim-fetch'
22 Plug 'mileszs/ack.vim'
23 Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
24 Plug 'sjl/gundo.vim'
25 Plug 'tangledhelix/vim-octopress'
26 Plug 'tpope/vim-fugitive'
27 Plug 'tpope/vim-git'
28 Plug 'tpope/vim-scriptease'
29 Plug 'tpope/vim-surround'
30 Plug 'tpope/vim-unimpaired'
31 Plug 'vim-airline/vim-airline'
32 Plug 'vim-airline/vim-airline-themes'
33 Plug '~/.vim/bundle/matchit'
34 Plug '~/.vim/bundle/mumps'
35 Plug '~/.vim/bundle/whitespace'
36 call plug#end()
37
38 " Automatic install
39 if empty(glob('~/.vim/plugged'))
40 autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
41 endif
42
43 " ---------------------------------------------------------------------------
44 " Terminal Settings
45 " ---------------------------------------------------------------------------
46
47 if !has("gui_running") && !(&term =~ '256color')
48 if has("terminfo") && ! (&term == 'linux' || &term == 'Eterm' || &term == 'vt220' || &term == 'nsterm-16color' || &term == 'xterm-16color')
49 " Force these terminals to accept my authority! (default)
50 set t_Co=16
51 set t_AB=\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm " ANSI background
52 set t_AF=\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm " ANSI foreground
53 elseif &term == 'term' || &term == 'rxvt' || &term == 'vt100' || &term == 'screen'
54 " Less-Cool Terminals (no terminfo)
55 set t_Co=16
56 set t_AB=\e[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
57 set t_AF=\e[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
58 else
59 " Terminals that have trustworthy terminfo entries
60 if &term == 'vt220'
61 set t_Co=8
62 set t_Sf=\e[3%dm " foreground
63 set t_Sb=\e[4%dm " background
64 elseif $TERM == 'xterm'
65 set term=xterm-color
66 endif
67 endif
68 endif
69
70 " ---------------------------------------------------------------------------
71 " Colors / Theme
72 " ---------------------------------------------------------------------------
73
74 if &t_Co > 2 || has("gui_running")
75 set background=dark " dark background
76 syntax enable " syntax highligting
77
78 " Solarized color-scheme
79 let g:solarized_termtrans=1 " Always use terminal's default bg color
80 colorscheme solarized
81 endif
82
83 " ---------------------------------------------------------------------------
84 " Highlight (Colors)
85 " ---------------------------------------------------------------------------
86
87 " comments
88 highlight Comment ctermfg=DarkGrey guifg=#425257
89 " visual block
90 highlight Visual term=reverse cterm=reverse ctermfg=DarkGreen ctermbg=White guifg=#4d830a guibg=#fdf6e3
91 " statusline (active vs inactive)
92 if !exists(':AirlineTheme')
93 highlight StatusLine term=reverse cterm=reverse ctermfg=Black ctermbg=Grey guifg=#073642 guibg=#93A1A1
94 highlight StatusLineNC term=reverse cterm=reverse ctermfg=Black ctermbg=DarkGrey guifg=#073642 guibg=#37555c
95 highlight User1 term=reverse cterm=reverse ctermfg=Black ctermbg=DarkGreen guifg=#4d830a guibg=#073642
96 endif
97 " unprintable chars (listchars)
98 highlight SpecialKey ctermfg=DarkGrey ctermbg=Black guifg=#374549 guibg=#06313c
99 " To-do comments
100 highlight Todo ctermfg=White ctermbg=Red guifg=#f2f2f2 guibg=#dc322f
101
102 " ----------------------------------------------------------------------------
103 " Backups
104 " ----------------------------------------------------------------------------
105
106 set nobackup " do not keep backups after close
107 set nowritebackup " do not keep a backup while working
108 set backupcopy=yes " keep attributes of original file
109 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
110 set directory=.,~/tmp,~/.vim/swap " swap file directory-order
111
112 " ----------------------------------------------------------------------------
113 " UI
114 " ----------------------------------------------------------------------------
115
116 set ruler " show the cursor position all the time
117 set showcmd " display incomplete commands
118 set nolazyredraw " turn off lazy redraw
119 set hidden " keep buffers loaded when hidden
120 set showmode " show mode at bottom of screen
121 set wildmenu " turn on wild menu
122 set wildmode=list:longest,full
123 set cmdheight=2 " command line height
124 set backspace=2 " allow backspacing over everything in insert mode
125 set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
126 set shortmess=filtIoO " shorten messages
127 set report=0 " tell us about changes
128 set nostartofline " don't jump to the start of line when scrolling
129 set scrolloff=4 " vertical padding
130 set sidescroll=40 " side-scrolling increment (for nowrap mode)
131 set sidescrolloff=10 " horz padding
132
133 " ----------------------------------------------------------------------------
134 " Visual Cues
135 " ----------------------------------------------------------------------------
136
137 set showmatch " brackets/braces that is
138 set matchtime=5 " duration to show matching brace (1/10 sec)
139 set incsearch " do incremental searching
140 set laststatus=2 " always show the status line
141 set ignorecase " ignore case when searching
142 set smartcase " case-sensitive if search contains an uppercase character
143 set visualbell " shut the heck up
144 set hlsearch " highlight all search matches
145 set list listchars=trail:·,tab:▸\ ,precedes:<,extends:> " show trailing whitespace and tab chars
146
147 " ----------------------------------------------------------------------------
148 " Status Line
149 " ----------------------------------------------------------------------------
150
151 if !exists(':AirlineTheme')
152 set statusline=%1*\ %n%0*\ %<%f " buffer #, filename
153 set statusline+=\ %h%m%r " file-state flags
154 set statusline+=%= " left-right divider
155 set statusline+=%{strlen(&fenc)?&fenc:&enc},%{&ff}\ %y " file-encoding, format, type
156 set statusline+=\ %12.(%v,%l/%L%)\ \ %-4P " cursor position, % through file of viewport
157 endif
158
159 let g:airline_theme='solarized16'
160 let g:airline_mode_map = {
161 \ '__' : '-',
162 \ 'n' : 'N',
163 \ 'i' : 'I',
164 \ 'R' : 'R',
165 \ 'c' : 'C',
166 \ 'v' : 'V',
167 \ 'V' : 'V',
168 \ '\16' : 'V',
169 \ 's' : 'S',
170 \ 'S' : 'S',
171 \ '\13' : 'S',
172 \ }
173 if !exists('g:airline_symbols')
174 let g:airline_symbols = {}
175 endif
176 if has("gui_running") || filereadable(expand("~/.vim/bundle/airline/.powerline_fonts_enabled"))
177 let g:airline_powerline_fonts = 1 " use powerline font symbols
178 else
179 let g:airline_symbols_ascii = 1 " use plain ascii symbols
180 let g:airline_symbols.branch = 'BR:'
181 endif
182 let g:airline_symbols.linenr = ''
183 let g:airline_symbols.maxlinenr = ''
184
185 " ----------------------------------------------------------------------------
186 " Text Formatting
187 " ----------------------------------------------------------------------------
188
189 set autoindent " automatic indent new lines
190 set smartindent " be smart about it
191 set nowrap " do not wrap lines
192 set softtabstop=2 " yep, two
193 set shiftwidth=2 " ..
194 set tabstop=4
195 set expandtab " expand tabs to spaces
196 set smarttab " smarter softtab handling
197 set formatoptions+=n " support for numbered/bullet lists
198 set textwidth=0 " no line-wrapping by default
199 set virtualedit=block " allow virtual edit in visual block ..
200 set spelllang=en_us " spell-check dictionary
201
202 " ----------------------------------------------------------------------------
203 " Filename exclusions
204 " ----------------------------------------------------------------------------
205
206 set wildignore+=.hg,.git,.svn " version control directories
207 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png " image files
208 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
209 set wildignore+=*.pyc " Python byte code
210 set wildignore+=*.sw? " Vim swap files
211 set wildignore+=.DS_Store " OSX junk
212
213 " ----------------------------------------------------------------------------
214 " Tabs
215 " ----------------------------------------------------------------------------
216
217 if version >= 700
218 set tabpagemax=50 " open 50 tabs max
219 endif
220
221 " ----------------------------------------------------------------------------
222 " Mappings
223 " ----------------------------------------------------------------------------
224
225 " movement based on display lines not physical lines (sane movement with wrap turned on)
226 nnoremap j gj
227 nnoremap k gk
228 vnoremap j gj
229 vnoremap k gk
230 nnoremap <Down> gj
231 nnoremap <Up> gk
232 vnoremap <Down> gj
233 vnoremap <Up> gk
234 inoremap <Down> <C-o>gj
235 inoremap <Up> <C-o>gk
236 " do not menu with left / right in command line
237 cnoremap <Left> <Space><BS><Left>
238 cnoremap <Right> <Space><BS><Right>
239
240 " reflow paragraph with Q in normal and visual mode
241 nnoremap Q gqap
242 vnoremap Q gq
243 " remap U to <C-r> for easier redo
244 nnoremap U <C-r>
245 " make Y consistent with C (c$) and D (d$)
246 nnoremap Y y$
247 " disable default vim regex handling for searching
248 nnoremap / /\v
249 vnoremap / /\v
250 " reselect visual block after indent/outdent
251 vnoremap < <gv
252 vnoremap > >gv
253
254 " <Space> to turn off highlighting and clear any message already displayed.
255 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
256
257 " leader-based keyboard shortcuts
258 let mapleader = ","
259 " CtrlP
260 nmap <leader>b :CtrlPBuffer<CR>
261 nmap <leader>o :CtrlP<CR>
262 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
263 " NERDTree
264 nmap <leader>d :NERDTreeToggle<CR>
265 nmap <leader>f :NERDTreeFind<CR>
266 " Gundo
267 nmap <leader>u :GundoToggle<CR>
268 " Fugitive (Git)
269 nmap <leader>gb :Gblame<CR>
270 nmap <leader>gs :Gstatus<CR>
271 nmap <leader>gd :Gdiff<CR>
272 nmap <leader>gl :Glog<CR>
273 nmap <leader>gc :Gcommit<CR>
274 nmap <leader>gp :Gpush<CR>
275 " cd to the directory containing the file in the buffer
276 nmap <leader>cd :lcd %:h<CR>
277 " toggle diffmode for a buffer
278 nmap <leader>df :call DiffToggle()<CR>
279 " quickly edit/reload vimrc
280 nmap <leader>ev :edit $MYVIMRC<CR>
281 nmap <leader>sv :source $MYVIMRC<CR>
282 " find merge conflict markers
283 nmap <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
284 " toggle hlsearch
285 nmap <leader>hs :set hlsearch! hlsearch?<CR>
286 " upper/lower word
287 nmap <leader>wu mQviwU`Q
288 nmap <leader>wl mQviwu`Q
289 " upper/lower first char of word
290 nmap <leader>wU mQgewvU`Q
291 nmap <leader>wL mQgewvu`Q
292 " smart paste - enable paste-mode and paste contents of system clipboard
293 map <leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
294 " strip all trailing whitespace in file
295 nmap <leader>sw :call whitespace#strip_trailing()<CR>
296 " toggle spell-check
297 nmap <leader>sp :setlocal spell! spell?<CR>
298 " set text wrapping toggles
299 nmap <leader>tw :set wrap! wrap?<CR>
300 " set list-whitespace-chars toggle
301 nmap <leader>ws :set list! list?<CR>
302 " open tag definition in a horz split
303 nmap <leader>tag :split <CR>:exec("tag ".expand("<cword>"))<CR>
304
305 " --------------------------------------------------------------------------
306 " Functions
307 " --------------------------------------------------------------------------
308
309 " Toggle diff-mode
310 function! DiffToggle()
311 if &diff
312 diffoff
313 else
314 diffthis
315 endif
316 endfunction
317
318 " Make a scratch buffer with all of the leader keybindings.
319 " Adapted from http://ctoomey.com/posts/an-incremental-approach-to-vim/
320 function! ListLeaders()
321 silent! redir @b
322 silent! nmap <LEADER>
323 silent! redir END
324 silent! new
325 silent! set buftype=nofile
326 silent! set bufhidden=hide
327 silent! setlocal noswapfile
328 silent! put! b
329 silent! g/^s*$/d
330 silent! %s/^.*,//
331 silent! normal ggVg
332 silent! sort
333 silent! let lines = getline(1,"$")
334 silent! normal <esc>
335 endfunction
336 command! ListLeaders :call ListLeaders()
337
338 " ----------------------------------------------------------------------------
339 " Plugin Settings
340 " ----------------------------------------------------------------------------
341
342 " NERDTree
343 let NERDTreeShowHidden=1 " show dotfiles by default
344 let NERDTreeMinimalUI=1 " disable 'Press ? for help' text
345 " Ctrl-P
346 let g:ctrlp_map = ''
347 let g:ctrlp_show_hidden = 1
348 let g:ctrlp_cache_dir = $HOME.'/.vim/.cache/ctrlp'
349 let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
350
351 " ---------------------------------------------------------------------------
352 " Auto Commands / File Types
353 " ---------------------------------------------------------------------------
354
355 augroup vimrc_autocmds
356 " clear auto command group so we don't define it multiple times
357 autocmd!
358 " jump to last position of buffer when opening (but not for commit messages)
359 au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$") |
360 \ exe "normal g'\"" | endif
361 " sh config
362 au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab
363 let g:is_bash = 1
364 " git commit message
365 au Filetype gitcommit set tw=68 spell
366 " html variants
367 au Filetype html,xml,xsl,rhtml source $HOME/.vim/scripts/closetag.vim
368 " don't use cindent for javascript
369 au FileType javascript setlocal nocindent
370 " use Octopress syntax-highlighting for *.markdown files
371 au BufNewFile,BufRead *.markdown set filetype=octopress spell
372 " in Makefiles, use real tabs not tabs expanded to spaces
373 au FileType make setlocal noexpandtab
374 augroup END
375
376 " --------------------------------------------------------------------------
377 " ManPageView
378 " --------------------------------------------------------------------------
379
380 let g:manpageview_pgm= 'man -P "/usr/bin/less -is"'
381 let $MANPAGER = '/usr/bin/less -is'
382
383 " --------------------------------------------------------------------------
384 " Local Settings
385 " --------------------------------------------------------------------------
386
387 if filereadable(glob("~/.vimrc.local"))
388 source ~/.vimrc.local
389 endif