1 " ---------------------------------------------------------------------------
3 " ---------------------------------------------------------------------------
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)
14 " ---------------------------------------------------------------------------
16 " ---------------------------------------------------------------------------
18 call plug#begin('~/.vim/plugged')
20 Plug 'altercation/vim-colors-solarized'
22 Plug 'kopischke/vim-fetch'
23 Plug 'mileszs/ack.vim'
24 Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
26 Plug 'tangledhelix/vim-octopress'
27 Plug 'tpope/vim-fugitive'
29 Plug 'tpope/vim-scriptease'
30 Plug 'tpope/vim-surround'
31 Plug 'tpope/vim-unimpaired'
32 Plug 'vim-airline/vim-airline'
33 Plug 'vim-airline/vim-airline-themes'
35 Plug '~/.vim/bundle/matchit'
36 Plug '~/.vim/bundle/mumps'
41 if empty(glob('~/.vim/plugged'))
42 autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
45 " ----------------------------------------------------------------------------
47 " ----------------------------------------------------------------------------
50 let NERDTreeShowHidden=1 " show dotfiles by default
51 let NERDTreeMinimalUI=1 " disable 'Press ? for help' text
55 let g:ctrlp_show_hidden = 1
56 let g:ctrlp_cache_dir = $HOME.'/.vim/.cache/ctrlp'
57 let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
60 let g:airline_mode_map = {
73 if !exists('g:airline_symbols')
74 let g:airline_symbols = {}
77 let g:airline_powerline_fonts = 1 " use powerline font symbols
79 let g:airline_symbols_ascii = 1 " use plain ascii symbols
80 let g:airline_symbols.branch = 'BR:'
82 let g:airline_symbols.linenr = ''
83 let g:airline_symbols.maxlinenr = ''
85 " ---------------------------------------------------------------------------
87 " ---------------------------------------------------------------------------
89 if !has("gui_running") && !(&term =~ '256color')
90 if has("terminfo") && ! (&term == 'linux' || &term == 'Eterm' || &term == 'vt220' || &term == 'nsterm-16color' || &term == 'xterm-16color')
91 " Force these terminals to accept my authority! (default)
93 set t_AB=
\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm " ANSI background
94 set t_AF=
\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm " ANSI foreground
95 elseif &term == 'term' || &term == 'rxvt' || &term == 'vt100' || &term == 'screen'
96 " Less-Cool Terminals (no terminfo)
98 set t_AB=
\e[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
99 set t_AF=
\e[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
101 " Terminals that have trustworthy terminfo entries
104 set t_Sf=
\e[3%dm " foreground
105 set t_Sb=
\e[4%dm " background
106 elseif $TERM == 'xterm'
112 " ---------------------------------------------------------------------------
114 " ---------------------------------------------------------------------------
116 if &t_Co > 2 || has("gui_running")
117 set background=dark " dark background
118 syntax enable " syntax highligting
120 let g:solarized_termcolors=&t_Co " use 256 colors for solarized
121 colorscheme solarized
123 let g:airline_theme='solarized16' " vim-airline theme
124 let g:solarized16_termcolors=16 " always use 16 colors for 'solarized16' vim-airline theme
127 " ---------------------------------------------------------------------------
129 " ---------------------------------------------------------------------------
131 if !has("gui_running")
132 " always use terminal's default bg color, override solarized Normal ctermfg
133 highlight Normal ctermbg=None ctermfg=None
134 " override solarized Comment ctermfg
136 highlight Comment ctermfg=241
138 highlight Comment ctermfg=DarkGrey
141 highlight Visual term=reverse cterm=reverse ctermfg=DarkGreen ctermbg=White
143 " unprintable chars (listchars)
144 highlight SpecialKey ctermfg=DarkGrey ctermbg=Black
148 " ----------------------------------------------------------------------------
150 " ----------------------------------------------------------------------------
152 set nobackup " do not keep backups after close
153 set nowritebackup " do not keep a backup while working
154 set backupcopy=yes " keep attributes of original file
155 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
156 set directory=.,~/tmp,~/.vim/swap " swap file directory-order
158 " ----------------------------------------------------------------------------
160 " ----------------------------------------------------------------------------
162 set ruler " show the cursor position all the time
163 set showcmd " display incomplete commands
164 set nolazyredraw " turn off lazy redraw
165 set hidden " keep buffers loaded when hidden
166 set showmode " show mode at bottom of screen
167 set wildmenu " turn on wild menu
168 set wildmode=list:longest,full
169 set cmdheight=2 " command line height
170 set backspace=2 " allow backspacing over everything in insert mode
171 set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
172 set shortmess=filtIoO " shorten messages
173 set report=0 " tell us about changes
174 set nostartofline " don't jump to the start of line when scrolling
175 set scrolloff=4 " vertical padding
176 set sidescroll=40 " side-scrolling increment (for nowrap mode)
177 set sidescrolloff=10 " horz padding
179 set tabpagemax=50 " open 50 tabs max
182 " ----------------------------------------------------------------------------
184 " ----------------------------------------------------------------------------
186 set showmatch " brackets/braces that is
187 set matchtime=5 " duration to show matching brace (1/10 sec)
188 set incsearch " do incremental searching
189 set laststatus=2 " always show the status line
190 set ignorecase " ignore case when searching
191 set smartcase " case-sensitive if search contains an uppercase character
192 set visualbell " shut the heck up
193 set hlsearch " highlight all search matches
194 set list listchars=trail:·,tab:▸\ ,precedes:<,extends:> " show trailing whitespace and tab chars
196 " ----------------------------------------------------------------------------
198 " ----------------------------------------------------------------------------
200 if !exists(':AirlineTheme')
201 set statusline=%1*\ %n%0*\ %<%f " buffer #, filename
202 set statusline+=\ %h%m%r " file-state flags
203 set statusline+=%= " left-right divider
204 set statusline+=%{strlen(&fenc)?&fenc:&enc},%{&ff}\ %y " file-encoding, format, type
205 set statusline+=\ %12.(%v,%l/%L%)\ \ %-4P " cursor position, % through file of viewport
208 " ----------------------------------------------------------------------------
210 " ----------------------------------------------------------------------------
212 set autoindent " automatic indent new lines
213 set smartindent " be smart about it
214 set nowrap " do not wrap lines
215 set softtabstop=2 " yep, two
216 set shiftwidth=2 " ..
218 set expandtab " expand tabs to spaces
219 set smarttab " smarter softtab handling
220 set formatoptions+=n " support for numbered/bullet lists
221 set textwidth=0 " no line-wrapping by default
222 set virtualedit=block " allow virtual edit in visual block ..
223 set spelllang=en_us " spell-check dictionary
225 " ----------------------------------------------------------------------------
226 " Filename Exclusions
227 " ----------------------------------------------------------------------------
229 set wildignore+=.hg,.git,.svn " version control directories
230 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png " image files
231 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
232 set wildignore+=*.pyc " Python byte code
233 set wildignore+=*.sw? " Vim swap files
234 set wildignore+=.DS_Store " OSX junk
236 " ----------------------------------------------------------------------------
238 " ----------------------------------------------------------------------------
240 " movement based on display lines not physical lines (sane movement with wrap turned on)
249 inoremap <Down> <C-o>gj
250 inoremap <Up> <C-o>gk
251 " do not menu with left / right in command line
252 cnoremap <Left> <Space><BS><Left>
253 cnoremap <Right> <Space><BS><Right>
255 " reflow paragraph with Q in normal and visual mode
258 " remap U to <C-r> for easier redo
260 " make Y consistent with C (c$) and D (d$)
262 " disable default vim regex handling for searching
265 " reselect visual block after indent/outdent
269 " <Space> to turn off highlighting and clear any message already displayed.
270 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
272 " leader-based keyboard shortcuts
275 nmap <leader>b :CtrlPBuffer<CR>
276 nmap <leader>o :CtrlP<CR>
277 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
279 nmap <leader>d :NERDTreeToggle<CR>
280 nmap <leader>f :NERDTreeFind<CR>
282 nmap <leader>u :GundoToggle<CR>
284 nmap <leader>gb :Gblame<CR>
285 nmap <leader>gs :Gstatus<CR>
286 nmap <leader>gd :Gdiff<CR>
287 nmap <leader>gl :Glog<CR>
288 nmap <leader>gc :Gcommit<CR>
289 nmap <leader>gp :Gpush<CR>
290 " cd to the directory containing the file in the buffer
291 nmap <leader>cd :lcd %:h<CR>
292 " toggle diffmode for a buffer
293 function! DiffToggle()
300 nmap <leader>df :call DiffToggle()<CR>
301 " quickly edit/reload vimrc
302 nmap <leader>ev :edit $MYVIMRC<CR>
303 nmap <leader>sv :source $MYVIMRC<CR>
304 " find merge conflict markers
305 nmap <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
307 nmap <leader>hls :set hlsearch! hlsearch?<CR>
309 nmap <leader>wu mQviwU`Q
310 nmap <leader>wl mQviwu`Q
311 " upper/lower first char of word
312 nmap <leader>wU mQgewvU`Q
313 nmap <leader>wL mQgewvu`Q
314 " smart paste - enable paste-mode and paste contents of system clipboard
315 map <leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
317 nmap <leader>sp :setlocal spell! spell?<CR>
318 " set text wrapping toggles
319 nmap <leader>tw :set wrap! wrap?<CR>
320 " set list-whitespace-chars toggle
321 nmap <leader>ws :set list! list?<CR>
322 " open tag definition in a horz split
323 nmap <leader>tag :split <CR>:exec("tag ".expand("<cword>"))<CR>
325 " --------------------------------------------------------------------------
327 " --------------------------------------------------------------------------
330 " Run vim command, redirect output to a scratch buffer
331 function! s:redir(cmd)
339 setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified
344 command! -nargs=+ -complete=command Redir call s:redir(<q-args>)
347 " Make a scratch buffer with all of the leader keybindings.
348 command! ListLeaders :call s:redir('nmap <leader>')
351 " Use `git grep` to search for to-do comments, add matches to qflist
352 function! s:todo() abort
354 for cmd in ['git grep -nI -e TODO -e FIXME -e XXX 2> /dev/null',
355 \ 'grep -rnI -e TODO -e FIXME -e XXX * 2> /dev/null']
356 let lines = split(system(cmd), '\n')
357 if v:shell_error != 0 | continue | endif
359 let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3]
360 call add(entries, { 'filename': fname, 'lnum': lno, 'text': text })
366 call setqflist(entries)
370 command! Todo call s:todo()
372 " :StripTrailingWhitespace
373 " Strip trailing whitespace
374 function! StripTrailingWhitespace()
375 " preparation: save last search, and cursor position.
381 " clean up: restore previous search history, and cursor position
385 command! StripTrailingWhitespace call StripTrailingWhitespace()
387 " ---------------------------------------------------------------------------
388 " Auto Commands / File Types
389 " ---------------------------------------------------------------------------
391 augroup vimrc_autocmds
392 " clear auto command group so we don't define it multiple times
394 " jump to last position of buffer when opening (but not for commit messages)
395 au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$") |
396 \ exe "normal g'\"" | endif
398 au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab
401 au Filetype gitcommit set tw=68 spell
402 " don't use cindent for javascript
403 au FileType javascript setlocal nocindent
404 " use Octopress syntax-highlighting for *.markdown files
405 au BufNewFile,BufRead *.markdown set filetype=octopress spell
406 " in Makefiles, use real tabs not tabs expanded to spaces
407 au FileType make setlocal noexpandtab
410 " --------------------------------------------------------------------------
412 " --------------------------------------------------------------------------
414 if filereadable(glob("~/.vimrc.local"))
415 source ~/.vimrc.local