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 " ---------------------------------------------------------------------------
15 " Pathogen Init (Bundles)
16 " ---------------------------------------------------------------------------
18 silent! call pathogen#infect()
19 silent! call pathogen#helptags()
20 filetype plugin indent on " enable plugins, detection and indenting in one step
22 " ---------------------------------------------------------------------------
24 " ---------------------------------------------------------------------------
26 if &t_Co > 2 || has("gui_running")
29 set t_AB=
\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm
30 set t_AF=
\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm
37 set background=dark " dark background
38 syntax enable " syntax highligting
40 " Define to-do color(s)
41 if !exists("autocmd_colorscheme_loaded")
42 let autocmd_colorscheme_loaded = 1
43 autocmd ColorScheme * highlight TodoRed ctermbg=LightRed guibg=#E01B1B ctermfg=White guifg=#002b37
46 " Solarized color-scheme
47 let g:solarized_termtrans=1 " Always use terminal's default bg color
50 " Auto-highlight TODO's
53 autocmd Syntax * call matchadd('TodoRed', '\W\zs\(TODO\)')
58 " ---------------------------------------------------------------------------
60 " ---------------------------------------------------------------------------
63 highlight Comment ctermfg=DarkGrey guifg=#425257
65 highlight Visual term=reverse cterm=reverse ctermfg=DarkGreen ctermbg=White guifg=#4d830a guibg=#fdf6e3
66 " statusline (active vs inactive)
67 highlight StatusLine term=reverse cterm=reverse ctermfg=Black ctermbg=Grey guifg=#073642 guibg=#93A1A1
68 highlight StatusLineNC term=reverse cterm=reverse ctermfg=Black ctermbg=DarkGrey guifg=#073642 guibg=#37555c
69 highlight User1 term=reverse cterm=reverse ctermfg=Black ctermbg=DarkGreen guifg=#4d830a guibg=#073642
70 " unprintable chars (listchars)
71 highlight SpecialKey ctermfg=DarkGray ctermbg=Black guifg=#374549 guibg=#06313c
73 " ----------------------------------------------------------------------------
75 " ----------------------------------------------------------------------------
77 set nobackup " do not keep backups after close
78 set nowritebackup " do not keep a backup while working
79 set backupcopy=yes " keep attributes of original file
80 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
81 set directory=.,~/tmp,~/.vim/swap " swap file directory-order
83 " ----------------------------------------------------------------------------
85 " ----------------------------------------------------------------------------
87 set ruler " show the cursor position all the time
88 set showcmd " display incomplete commands
89 set nolazyredraw " turn off lazy redraw
90 set hidden " keep buffers loaded when hidden
91 set showmode " show mode at bottom of screen
92 set wildmenu " turn on wild menu
93 set wildmode=list:longest,full
94 set cmdheight=2 " command line height
95 set backspace=2 " allow backspacing over everything in insert mode
96 set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
97 set shortmess=filtIoO " shorten messages
98 set report=0 " tell us about changes
99 set nostartofline " don't jump to the start of line when scrolling
100 set scrolloff=4 " vertical padding
101 set sidescroll=40 " side-scrolling increment (for nowrap mode)
102 set sidescrolloff=10 " horz padding
104 " ----------------------------------------------------------------------------
106 " ----------------------------------------------------------------------------
108 set showmatch " brackets/braces that is
109 set matchtime=5 " duration to show matching brace (1/10 sec)
110 set incsearch " do incremental searching
111 set laststatus=2 " always show the status line
112 set ignorecase " ignore case when searching
113 set smartcase " case-sensitive if search contains an uppercase character
114 set visualbell " shut the heck up
115 set hlsearch " highlight all search matches
116 set list listchars=trail:·,tab:▸\ ,precedes:<,extends:> " show trailing whitespace and tab chars
118 " ----------------------------------------------------------------------------
120 " ----------------------------------------------------------------------------
122 set statusline=%1*\ %n%0*\ %<%f " buffer #, filename
123 set statusline+=\ %h%m%r " file-state flags
124 set statusline+=%= " left-right divider
125 set statusline+=%{strlen(&fenc)?&fenc:&enc},%{&ff}\ %y " file-encoding, format, type
126 set statusline+=\ %12.(%v,%l/%L%)\ \ %-4P " cursor position, % through file of viewport
128 let g:airline_theme='solarized16'
129 if !exists('g:airline_symbols')
130 let g:airline_symbols = {}
132 let g:airline_left_sep = ''
133 let g:airline_right_sep = ''
134 let g:airline_symbols.branch = 'BR:'
135 let g:airline_symbols.linenr = ''
136 let g:airline_symbols.maxlinenr = ''
138 " ----------------------------------------------------------------------------
140 " ----------------------------------------------------------------------------
142 set autoindent " automatic indent new lines
143 set smartindent " be smart about it
144 set nowrap " do not wrap lines
145 set softtabstop=2 " yep, two
146 set shiftwidth=2 " ..
148 set expandtab " expand tabs to spaces
149 set smarttab " smarter softtab handling
150 set formatoptions+=n " support for numbered/bullet lists
151 set textwidth=0 " no line-wrapping by default
152 set virtualedit=block " allow virtual edit in visual block ..
153 set spelllang=en_us " spell-check dictionary
155 " ----------------------------------------------------------------------------
156 " Filename exclusions
157 " ----------------------------------------------------------------------------
159 set wildignore+=.hg,.git,.svn " version control directories
160 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png " image files
161 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
162 set wildignore+=*.pyc " Python byte code
163 set wildignore+=*.sw? " Vim swap files
164 set wildignore+=.DS_Store " OSX junk
166 " ----------------------------------------------------------------------------
168 " ----------------------------------------------------------------------------
171 set tabpagemax=50 " open 50 tabs max
174 " ----------------------------------------------------------------------------
176 " ----------------------------------------------------------------------------
178 " movement based on display lines not physical lines (sane movement with wrap turned on)
187 inoremap <Down> <C-o>gj
188 inoremap <Up> <C-o>gk
189 " do not menu with left / right in command line
190 cnoremap <Left> <Space><BS><Left>
191 cnoremap <Right> <Space><BS><Right>
193 " reflow paragraph with Q in normal and visual mode
196 " remap U to <C-r> for easier redo
198 " make Y consistent with C (c$) and D (d$)
200 " disable default vim regex handling for searching
203 " reselect visual block after indent/outdent
207 " <Space> to turn off highlighting and clear any message already displayed.
208 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
209 " <F4> to toggle NERDTree
210 nnoremap <F4> :NERDTreeToggle<CR>
211 " <F5> to toggle Gundo
212 nnoremap <F5> :GundoToggle<CR>
214 " leader-based keyboard shortcuts
217 nmap <leader>b :CtrlPBuffer<CR>
218 nmap <leader>o :CtrlP<CR>
219 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
221 nmap <leader>d :NERDTreeToggle<CR>
222 nmap <leader>f :NERDTreeFind<CR>
224 nmap <leader>gb :Gblame<CR>
225 nmap <leader>gs :Gstatus<CR>
226 nmap <leader>gd :Gdiff<CR>
227 nmap <leader>gl :Glog<CR>
228 nmap <leader>gc :Gcommit<CR>
229 nmap <leader>gp :Gpush<CR>
230 " cd to the directory containing the file in the buffer
231 nmap <leader>cd :lcd %:h<CR>
232 " toggle diffmode for a buffer
233 nmap <leader>df :call DiffToggle()<CR>
234 " quickly edit/reload vimrc
235 nmap <leader>ev :edit $MYVIMRC<CR>
236 nmap <leader>sv :source $MYVIMRC<CR>
237 " find merge conflict markers
238 nmap <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
240 nmap <leader>hs :set hlsearch! hlsearch?<CR>
242 nmap <leader>wu mQviwU`Q
243 nmap <leader>wl mQviwu`Q
244 " upper/lower first char of word
245 nmap <leader>wU mQgewvU`Q
246 nmap <leader>wL mQgewvu`Q
247 " smart paste - enable paste-mode and paste contents of system clipboard
248 map <leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
250 nmap <leader>r :redraw!<CR>
251 " strip all trailing whitespace in file
252 nmap <leader>sw :call whitespace#strip_trailing()<CR>
254 nmap <leader>sp :setlocal spell! spell?<CR>
255 " set text wrapping toggles
256 nmap <leader>tw :set wrap! wrap?<CR>
257 " set list-whitespace-chars toggle
258 nmap <leader>ws :set list! list?<CR>
260 " --------------------------------------------------------------------------
262 " --------------------------------------------------------------------------
265 function! DiffToggle()
273 " Make a scratch buffer with all of the leader keybindings.
274 " Adapted from http://ctoomey.com/posts/an-incremental-approach-to-vim/
275 function! ListLeaders()
277 silent! nmap <LEADER>
280 silent! set buftype=nofile
281 silent! set bufhidden=hide
282 silent! setlocal noswapfile
288 silent! let lines = getline(1,"$")
291 command! ListLeaders :call ListLeaders()
293 " ----------------------------------------------------------------------------
295 " ----------------------------------------------------------------------------
298 let NERDTreeShowHidden=1 " show dotfiles by default
301 let g:ctrlp_show_hidden = 1
302 let g:ctrlp_cache_dir = $HOME.'/.vim/.cache/ctrlp'
304 " ---------------------------------------------------------------------------
305 " Auto Commands / File Types
306 " ---------------------------------------------------------------------------
308 augroup vimrc_autocmds
309 " clear auto command group so we don't define it multiple times
311 " jump to last position of buffer when opening (but not for commit messages)
312 au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$") |
313 \ exe "normal g'\"" | endif
315 au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab
318 au Filetype gitcommit set tw=68 spell
320 au Filetype html,xml,xsl,rhtml source $HOME/.vim/scripts/closetag.vim
321 " don't use cindent for javascript
322 au FileType javascript setlocal nocindent
323 " use Octopress syntax-highlighting for *.markdown files
324 au BufNewFile,BufRead *.markdown set filetype=octopress spell
325 " in Makefiles, use real tabs not tabs expanded to spaces
326 au FileType make setlocal noexpandtab
329 " --------------------------------------------------------------------------
331 " --------------------------------------------------------------------------
333 let g:manpageview_pgm= 'man -P "/usr/bin/less -is"'
334 let $MANPAGER = '/usr/bin/less -is'