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