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'
24 Plug 'scrooloose/nerdtree'
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 " ---------------------------------------------------------------------------
47 if &t_Co > 2 || has("gui_running")
50 set t_AB=
\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm
51 set t_AF=
\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm
58 set background=dark " dark background
59 syntax enable " syntax highligting
61 " Define to-do color(s)
62 if !exists("autocmd_colorscheme_loaded")
63 let autocmd_colorscheme_loaded = 1
64 autocmd ColorScheme * highlight TodoRed ctermbg=LightRed guibg=#E01B1B ctermfg=White guifg=#002b37
67 " Solarized color-scheme
68 let g:solarized_termtrans=1 " Always use terminal's default bg color
71 " Auto-highlight TODO's
74 autocmd Syntax * call matchadd('TodoRed', '\W\zs\(TODO\)')
79 " ---------------------------------------------------------------------------
81 " ---------------------------------------------------------------------------
84 highlight Comment ctermfg=DarkGrey guifg=#425257
86 highlight Visual term=reverse cterm=reverse ctermfg=DarkGreen ctermbg=White guifg=#4d830a guibg=#fdf6e3
87 "" statusline (active vs inactive)
88 if !exists(':AirlineTheme')
89 highlight StatusLine term=reverse cterm=reverse ctermfg=Black ctermbg=Grey guifg=#073642 guibg=#93A1A1
90 highlight StatusLineNC term=reverse cterm=reverse ctermfg=Black ctermbg=DarkGrey guifg=#073642 guibg=#37555c
91 highlight User1 term=reverse cterm=reverse ctermfg=Black ctermbg=DarkGreen guifg=#4d830a guibg=#073642
93 " unprintable chars (listchars)
94 highlight SpecialKey ctermfg=DarkGray ctermbg=Black guifg=#374549 guibg=#06313c
96 " ----------------------------------------------------------------------------
98 " ----------------------------------------------------------------------------
100 set nobackup " do not keep backups after close
101 set nowritebackup " do not keep a backup while working
102 set backupcopy=yes " keep attributes of original file
103 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
104 set directory=.,~/tmp,~/.vim/swap " swap file directory-order
106 " ----------------------------------------------------------------------------
108 " ----------------------------------------------------------------------------
110 set ruler " show the cursor position all the time
111 set showcmd " display incomplete commands
112 set nolazyredraw " turn off lazy redraw
113 set hidden " keep buffers loaded when hidden
114 set showmode " show mode at bottom of screen
115 set wildmenu " turn on wild menu
116 set wildmode=list:longest,full
117 set cmdheight=2 " command line height
118 set backspace=2 " allow backspacing over everything in insert mode
119 set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
120 set shortmess=filtIoO " shorten messages
121 set report=0 " tell us about changes
122 set nostartofline " don't jump to the start of line when scrolling
123 set scrolloff=4 " vertical padding
124 set sidescroll=40 " side-scrolling increment (for nowrap mode)
125 set sidescrolloff=10 " horz padding
127 " ----------------------------------------------------------------------------
129 " ----------------------------------------------------------------------------
131 set showmatch " brackets/braces that is
132 set matchtime=5 " duration to show matching brace (1/10 sec)
133 set incsearch " do incremental searching
134 set laststatus=2 " always show the status line
135 set ignorecase " ignore case when searching
136 set smartcase " case-sensitive if search contains an uppercase character
137 set visualbell " shut the heck up
138 set hlsearch " highlight all search matches
139 set list listchars=trail:·,tab:▸\ ,precedes:<,extends:> " show trailing whitespace and tab chars
141 " ----------------------------------------------------------------------------
143 " ----------------------------------------------------------------------------
145 if !exists(':AirlineTheme')
146 set statusline=%1*\ %n%0*\ %<%f " buffer #, filename
147 set statusline+=\ %h%m%r " file-state flags
148 set statusline+=%= " left-right divider
149 set statusline+=%{strlen(&fenc)?&fenc:&enc},%{&ff}\ %y " file-encoding, format, type
150 set statusline+=\ %12.(%v,%l/%L%)\ \ %-4P " cursor position, % through file of viewport
153 let g:airline_theme='solarized16'
154 let g:airline_mode_map = {
167 if !exists('g:airline_symbols')
168 let g:airline_symbols = {}
170 if has("gui_running") || filereadable(expand("~/.vim/bundle/airline/.powerline_fonts_enabled"))
171 let g:airline_powerline_fonts = 1 " use powerline font symbols
173 let g:airline_symbols_ascii = 1 " use plain ascii symbols
174 let g:airline_symbols.branch = 'BR:'
176 let g:airline_symbols.linenr = ''
177 let g:airline_symbols.maxlinenr = ''
179 " ----------------------------------------------------------------------------
181 " ----------------------------------------------------------------------------
183 set autoindent " automatic indent new lines
184 set smartindent " be smart about it
185 set nowrap " do not wrap lines
186 set softtabstop=2 " yep, two
187 set shiftwidth=2 " ..
189 set expandtab " expand tabs to spaces
190 set smarttab " smarter softtab handling
191 set formatoptions+=n " support for numbered/bullet lists
192 set textwidth=0 " no line-wrapping by default
193 set virtualedit=block " allow virtual edit in visual block ..
194 set spelllang=en_us " spell-check dictionary
196 " ----------------------------------------------------------------------------
197 " Filename exclusions
198 " ----------------------------------------------------------------------------
200 set wildignore+=.hg,.git,.svn " version control directories
201 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png " image files
202 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
203 set wildignore+=*.pyc " Python byte code
204 set wildignore+=*.sw? " Vim swap files
205 set wildignore+=.DS_Store " OSX junk
207 " ----------------------------------------------------------------------------
209 " ----------------------------------------------------------------------------
212 set tabpagemax=50 " open 50 tabs max
215 " ----------------------------------------------------------------------------
217 " ----------------------------------------------------------------------------
219 " movement based on display lines not physical lines (sane movement with wrap turned on)
228 inoremap <Down> <C-o>gj
229 inoremap <Up> <C-o>gk
230 " do not menu with left / right in command line
231 cnoremap <Left> <Space><BS><Left>
232 cnoremap <Right> <Space><BS><Right>
234 " reflow paragraph with Q in normal and visual mode
237 " remap U to <C-r> for easier redo
239 " make Y consistent with C (c$) and D (d$)
241 " disable default vim regex handling for searching
244 " reselect visual block after indent/outdent
248 " <Space> to turn off highlighting and clear any message already displayed.
249 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
251 " leader-based keyboard shortcuts
254 nmap <leader>b :CtrlPBuffer<CR>
255 nmap <leader>o :CtrlP<CR>
256 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
258 nmap <leader>d :NERDTreeToggle<CR>
259 nmap <leader>f :NERDTreeFind<CR>
261 nmap <leader>u :GundoToggle<CR>
263 nmap <leader>gb :Gblame<CR>
264 nmap <leader>gs :Gstatus<CR>
265 nmap <leader>gd :Gdiff<CR>
266 nmap <leader>gl :Glog<CR>
267 nmap <leader>gc :Gcommit<CR>
268 nmap <leader>gp :Gpush<CR>
269 " cd to the directory containing the file in the buffer
270 nmap <leader>cd :lcd %:h<CR>
271 " toggle diffmode for a buffer
272 nmap <leader>df :call DiffToggle()<CR>
273 " quickly edit/reload vimrc
274 nmap <leader>ev :edit $MYVIMRC<CR>
275 nmap <leader>sv :source $MYVIMRC<CR>
276 " find merge conflict markers
277 nmap <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
279 nmap <leader>hs :set hlsearch! hlsearch?<CR>
281 nmap <leader>wu mQviwU`Q
282 nmap <leader>wl mQviwu`Q
283 " upper/lower first char of word
284 nmap <leader>wU mQgewvU`Q
285 nmap <leader>wL mQgewvu`Q
286 " smart paste - enable paste-mode and paste contents of system clipboard
287 map <leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
288 " strip all trailing whitespace in file
289 nmap <leader>sw :call whitespace#strip_trailing()<CR>
291 nmap <leader>sp :setlocal spell! spell?<CR>
292 " set text wrapping toggles
293 nmap <leader>tw :set wrap! wrap?<CR>
294 " set list-whitespace-chars toggle
295 nmap <leader>ws :set list! list?<CR>
296 " open tag definition in a horz split
297 nmap <leader>tag :split <CR>:exec("tag ".expand("<cword>"))<CR>
299 " --------------------------------------------------------------------------
301 " --------------------------------------------------------------------------
304 function! DiffToggle()
312 " Make a scratch buffer with all of the leader keybindings.
313 " Adapted from http://ctoomey.com/posts/an-incremental-approach-to-vim/
314 function! ListLeaders()
316 silent! nmap <LEADER>
319 silent! set buftype=nofile
320 silent! set bufhidden=hide
321 silent! setlocal noswapfile
327 silent! let lines = getline(1,"$")
330 command! ListLeaders :call ListLeaders()
332 " ----------------------------------------------------------------------------
334 " ----------------------------------------------------------------------------
337 let NERDTreeShowHidden=1 " show dotfiles by default
338 let NERDTreeMinimalUI=1 " disable 'Press ? for help' text
341 let g:ctrlp_show_hidden = 1
342 let g:ctrlp_cache_dir = $HOME.'/.vim/.cache/ctrlp'
343 let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
345 " ---------------------------------------------------------------------------
346 " Auto Commands / File Types
347 " ---------------------------------------------------------------------------
349 augroup vimrc_autocmds
350 " clear auto command group so we don't define it multiple times
352 " jump to last position of buffer when opening (but not for commit messages)
353 au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$") |
354 \ exe "normal g'\"" | endif
356 au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab
359 au Filetype gitcommit set tw=68 spell
361 au Filetype html,xml,xsl,rhtml source $HOME/.vim/scripts/closetag.vim
362 " don't use cindent for javascript
363 au FileType javascript setlocal nocindent
364 " use Octopress syntax-highlighting for *.markdown files
365 au BufNewFile,BufRead *.markdown set filetype=octopress spell
366 " in Makefiles, use real tabs not tabs expanded to spaces
367 au FileType make setlocal noexpandtab
370 " --------------------------------------------------------------------------
372 " --------------------------------------------------------------------------
374 let g:manpageview_pgm= 'man -P "/usr/bin/less -is"'
375 let $MANPAGER = '/usr/bin/less -is'