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