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