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')
19 Plug 'altercation/vim-colors-solarized'
21 Plug 'kopischke/vim-fetch'
22 Plug 'mileszs/ack.vim'
23 Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
25 Plug 'tangledhelix/vim-octopress'
26 Plug 'tpope/vim-fugitive'
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'
39 if empty(glob('~/.vim/plugged'))
40 autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
43 " ----------------------------------------------------------------------------
45 " ----------------------------------------------------------------------------
48 let NERDTreeShowHidden=1 " show dotfiles by default
49 let NERDTreeMinimalUI=1 " disable 'Press ? for help' text
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']
58 let g:airline_mode_map = {
71 if !exists('g:airline_symbols')
72 let g:airline_symbols = {}
75 let g:airline_powerline_fonts = 1 " use powerline font symbols
77 let g:airline_symbols_ascii = 1 " use plain ascii symbols
78 let g:airline_symbols.branch = 'BR:'
80 let g:airline_symbols.linenr = ''
81 let g:airline_symbols.maxlinenr = ''
83 " ---------------------------------------------------------------------------
85 " ---------------------------------------------------------------------------
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)
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)
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
99 " Terminals that have trustworthy terminfo entries
102 set t_Sf=
\e[3%dm " foreground
103 set t_Sb=
\e[4%dm " background
104 elseif $TERM == 'xterm'
110 " ---------------------------------------------------------------------------
112 " ---------------------------------------------------------------------------
114 if &t_Co > 2 || has("gui_running")
115 set background=dark " dark background
116 syntax enable " syntax highligting
119 let g:solarized_termcolors=256 " use 256 colors for solarized
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
126 " ---------------------------------------------------------------------------
128 " ---------------------------------------------------------------------------
130 " always use terminal's default bg color
131 highlight Normal ctermbg=None
133 highlight Comment ctermfg=DarkGrey
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
141 " ----------------------------------------------------------------------------
143 " ----------------------------------------------------------------------------
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
151 " ----------------------------------------------------------------------------
153 " ----------------------------------------------------------------------------
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
172 set tabpagemax=50 " open 50 tabs max
175 " ----------------------------------------------------------------------------
177 " ----------------------------------------------------------------------------
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
189 " ----------------------------------------------------------------------------
191 " ----------------------------------------------------------------------------
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
201 " ----------------------------------------------------------------------------
203 " ----------------------------------------------------------------------------
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 " ..
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
218 " ----------------------------------------------------------------------------
219 " Filename Exclusions
220 " ----------------------------------------------------------------------------
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
229 " ----------------------------------------------------------------------------
231 " ----------------------------------------------------------------------------
233 " movement based on display lines not physical lines (sane movement with wrap turned on)
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>
248 " reflow paragraph with Q in normal and visual mode
251 " remap U to <C-r> for easier redo
253 " make Y consistent with C (c$) and D (d$)
255 " disable default vim regex handling for searching
258 " reselect visual block after indent/outdent
262 " <Space> to turn off highlighting and clear any message already displayed.
263 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
265 " leader-based keyboard shortcuts
268 nmap <leader>b :CtrlPBuffer<CR>
269 nmap <leader>o :CtrlP<CR>
270 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
272 nmap <leader>d :NERDTreeToggle<CR>
273 nmap <leader>f :NERDTreeFind<CR>
275 nmap <leader>u :GundoToggle<CR>
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>
293 nmap <leader>hs :set hlsearch! hlsearch?<CR>
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>
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>
313 " --------------------------------------------------------------------------
315 " --------------------------------------------------------------------------
318 function! DiffToggle()
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()
330 silent! nmap <LEADER>
333 silent! set buftype=nofile
334 silent! set bufhidden=hide
335 silent! setlocal noswapfile
341 silent! let lines = getline(1,"$")
344 command! ListLeaders :call ListLeaders()
346 " ---------------------------------------------------------------------------
347 " Auto Commands / File Types
348 " ---------------------------------------------------------------------------
350 augroup vimrc_autocmds
351 " clear auto command group so we don't define it multiple times
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
357 au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab
360 au Filetype gitcommit set tw=68 spell
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
371 " --------------------------------------------------------------------------
373 " --------------------------------------------------------------------------
375 if filereadable(glob("~/.vimrc.local"))
376 source ~/.vimrc.local