Last active
August 29, 2015 14:01
-
-
Save brandonpittman/3c4366c548a6d6ab1c61 to your computer and use it in GitHub Desktop.
.vimrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vundle Setup {{{1 | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
" Source Vundle Plugins {{{1 | |
if filereadable(expand("~/.vimrc.bundles")) | |
source ~/.vimrc.bundles | |
endif | |
" Vundle Teardown {{{1 | |
call vundle#end() | |
filetype plugin indent on | |
" Leaders {{{1 | |
let mapleader = " " | |
let maplocalleader = "," | |
" Preferences {{{1 | |
set sw=2 sts=2 ts=2 et | |
set shiftround | |
set encoding=utf-8 | |
set ignorecase smartcase | |
set hlsearch | |
set number | |
set numberwidth=5 | |
set clipboard=unnamed | |
set backspace=indent,eol,start " allow backspacing over everything in insert mode | |
set nowritebackup | |
set nobackup | |
set noswapfile | |
set backspace=2 | |
set nocompatible | |
set history=100 | |
set hidden | |
set ruler | |
set showcmd | |
set incsearch | |
set laststatus=2 | |
set foldmethod=syntax | |
set foldlevel=3 | |
set cursorline cursorcolumn | |
set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P | |
set wildmenu | |
set wildmode=full | |
set background=dark | |
colorscheme Tomorrow-Night-Bright | |
set guifont=Bitstream\ Vera\ Sans\ Mono:h18 | |
" ctags | |
set tags+=gems.tags | |
" Set 81st column to colorized | |
highlight ColorColumn ctermbg=magenta | |
call matchadd('ColorColumn', '\%81v', 100) | |
" set up some custom colors | |
highlight clear SignColumn | |
highlight VertSplit ctermbg=236 | |
highlight ColorColumn ctermbg=237 | |
highlight LineNr ctermbg=236 ctermfg=240 | |
highlight CursorLineNr ctermbg=236 ctermfg=240 | |
highlight CursorLine ctermbg=236 | |
highlight StatusLineNC ctermbg=238 ctermfg=0 | |
highlight StatusLine ctermbg=240 ctermfg=12 | |
highlight IncSearch ctermbg=3 ctermfg=1 | |
highlight Search ctermbg=1 ctermfg=3 | |
highlight Visual ctermbg=3 ctermfg=0 | |
highlight Pmenu ctermbg=240 ctermfg=12 | |
highlight PmenuSel ctermbg=3 ctermfg=1 | |
highlight SpellBad ctermbg=0 ctermfg=1 | |
highlight SignColumn ctermbg=black | |
" Make spaces and tabs visible | |
exec "set listchars=tab:\uBB\uBB,trail:\uB7,nbsp:~" | |
set list | |
" Exclude Javascript files in :Rtags via rails.vim due to warnings when parsing | |
let g:Tlist_Ctags_Cmd="ctags --exclude='*.js'" | |
" Treat <li> and <p> tags like the block tags they are | |
let g:html_indent_tags = 'li\|p' | |
" Open new split panes to right and bottom, which feels more natural | |
set splitbelow | |
set splitright | |
" configure syntastic syntax checking to check on open as well as save | |
let g:syntastic_check_on_open=1 | |
" In many terminal emulators the mouse works just fine, thus enable it. | |
if has('mouse') | |
set mouse=a | |
endif | |
" Turn on highlighting | |
if (&t_Co > 2 || has("gui_running")) && !exists("syntax_on") | |
syntax on | |
endif | |
set t_Co=256 | |
if !exists(":DiffOrig") | |
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis | |
\ | wincmd p | diffthis | |
endif | |
" Supposedly makes vim respect more standard shell syntax | |
let g:is_posix = 1 | |
" Set the tag file search order | |
set tags=./tags; | |
" Display extra whitespace | |
set list listchars=tab:»·,trail:· | |
" Use The Silver Searcher https://github.com/ggreer/the_silver_searcher | |
if executable('ag') | |
" Use Ag over Grep | |
set grepprg=ag\ --nogroup\ --nocolor | |
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore | |
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""' | |
" ag is fast enough that CtrlP doesn't need to cache | |
let g:ctrlp_use_caching = 0 | |
endif | |
" Snippets are activated by Shift+Tab | |
"let g:snippetsEmu_key = "<S-Tab>" | |
" Tab completion | |
" will insert tab at beginning of line, | |
" will use completion if not at beginning | |
"set wildmode=list:longest,list:full | |
"set complete=.,w,t | |
" Gist enhancements | |
let g:gist_detect_filetype = 1 | |
let g:gist_open_browser_after_post = 1 | |
let g:gist_clip_command = 'pbcopy' | |
let g:gist_show_privates = 1 | |
let g:gist_get_multiplefile = 1 | |
" Remaps {{{1 | |
" Fix spelling mistakes | |
imap <c-f> <c-g>u<Esc>[s1z=`]a<c-g>u | |
nmap <c-f> [s1z=<c-o>]`] | |
" vim-bookmarks | |
" nmap <Leader><Leader> <Plug>ToggleBookmark | |
" nmap <Leader>i <Plug>Annotate | |
" nmap <Leader>a <Plug>ShowAllBookmarks | |
" nmap <Leader>j <Plug>NextBookmark | |
" nmap <Leader>k <Plug>PrevBookmark | |
" nmap <Leader>c <Plug>ClearBookmarks | |
" nmap <Leader>x <Plug>ClearAllBookmarks | |
" Set Par as formatter | |
set formatprg=par | |
" Ctrl-P | |
nnoremap <leader>. :CtrlPTag<cr> | |
" This rewires n and N to do the highlighing... | |
nnoremap <silent> n n:call HLNext(0.4)<cr> | |
nnoremap <silent> N N:call HLNext(0.4)<cr> | |
" Remaps for visual modes | |
nnoremap v <C-V> | |
nnoremap <C-V> v | |
vnoremap v <C-V> | |
vnoremap <C-V> v | |
" map markdown preview | |
map <leader>m :!open -a Marked %<cr><cr> | |
" Re-run last substitute | |
nnoremap & :&&<CR> | |
xnoremap & :&&<CR> | |
" Cancel hlsearch | |
nnoremap <silent> <CR> :noh<CR><CR> | |
" Let's be reasonable, shall we? | |
nmap k gk | |
nmap j gj | |
cnoremap <C-p> <Up> | |
cnoremap <C-n> <Down> | |
cnoremap %% <C-R>=fnameescape(expand('%:h')).'/'<Cr> | |
map <Leader>ew :e %% | |
map <Leader>es :sp %% | |
map <Leader>ev :vsp %% | |
map <Leader>et :tabe %% | |
" Rails Remaps | |
map <Leader>ac :sp app/controllers/application_controller.rb<cr> | |
vmap <Leader>b :<C-U>!git blame <C-R>=expand("%:p") <CR> \| sed -n <C-R>=line("'<") <CR>,<C-R>=line("'>") <CR>p <CR> | |
map <Leader>bb :!bundle install<cr> | |
nmap <Leader>bi :source ~/.vimrc.bundles<cr>:BundleInstall<cr> | |
" Tabularize shortcuts {{{2 | |
if exists(":Tabularize") | |
nmap <Leader>a= :Tabularize /=<CR> | |
vmap <Leader>a= :Tabularize /=<CR> | |
nmap <Leader>a: :Tabularize /:\zs<CR> | |
vmap <Leader>a: :Tabularize /:\zs<CR> | |
endif | |
" Keep tabular data tabular automagically | |
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a | |
"GundoToggle | |
nnoremap <Leader>gt :GundoToggle<CR> | |
" Don't use Ex mode, use Q for formatting | |
noremap Q gq | |
"Quick Edits | |
map <Leader>dr :e ~/Dropbox<cr> | |
map <Leader>ec :e ~/Dropbox/Documents/Code/ | |
map <Leader>md :e ~/Dropbox/Documents/Markdown | |
map <Leader>rb :e ~/Dropbox/Documents/Code/Ruby | |
map <Leader>sh :e ~/Dropbox/Documents/Code/Shell\ Scripts | |
map <Leader>sn :e ~/.vim/snippets/ruby.snippets<CR> | |
"Update Gcommit behavior | |
map <Leader>gac :Gcommit -m -a ""<LEFT> | |
map <Leader>gc :Gcommit -m ""<LEFT> | |
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo, | |
" so that you can undo CTRL-U after inserting a line break. | |
inoremap <C-U> <C-G>u<C-U> | |
" Delete line | |
inoremap <C-d> <esc>ddi | |
" Open vimrc in vertical split | |
nnoremap <Leader>v :tabedit $MYVIMRC<Cr> | |
" Source vimrc while Vim's still open | |
nnoremap <Leader>sr :source $MYVIMRC<Cr> | |
" Jump to start of line | |
nnoremap H ^ | |
" Jump to end of line | |
nnoremap L $ | |
" Insert mode >> Normal mode | |
inoremap jk <esc> | |
" Insert-Normal Mode | |
inoremap jl <C-o> | |
" Enter Visual block mode | |
nmap <Leader>V <C-V> | |
" Quick save | |
nnoremap <Leader>w :w<CR> | |
" Quick quit | |
nnoremap <Leader>q :wq<CR> | |
nnoremap <Leader>Q :q!<CR> | |
" Quick open | |
nnoremap <Leader>o :CtrlP<CR> | |
" System clipboard copy & paste | |
vmap <Leader>y "+y | |
vmap <Leader>d "+d | |
nmap <Leader>p "+p | |
nmap <Leader>P "+P | |
vmap <Leader>p "+p | |
vmap <Leader>P "+P | |
" Auto-indent everything | |
nnoremap <Leader>= gg=G | |
"Override Replace mode | |
nnoremap R gR | |
" Index ctags from any project, including those outside Rails | |
noremap <Leader>ct :!ctags -R .<CR> | |
" Switch between the last two files | |
"nnoremap <Leader><Leader> <C-^> | |
" Toggle fold | |
nnoremap <Leader><Leader> zA | |
nnoremap <Leader>1 :set foldlevel=1<CR> | |
nnoremap <Leader>2 :set foldlevel=2<CR> | |
" Get off my lawn | |
nnoremap <Left> :echoe "Use h"<CR> | |
nnoremap <Right> :echoe "Use l"<CR> | |
nnoremap <Up> :echoe "Use k"<CR> | |
nnoremap <Down> :echoe "Use j"<CR> | |
" vim-rspec mappings | |
nnoremap <Leader>t :call RunCurrentSpecFile()<CR> | |
nnoremap <Leader>s :call RunNearestSpec()<CR> | |
nnoremap <Leader>l :call RunLastSpec()<CR> | |
" Quicker window movement | |
nnoremap <C-j> <C-w>j | |
nnoremap <C-k> <C-w>k | |
nnoremap <C-h> <C-w>h | |
nnoremap <C-l> <C-w>l | |
nnoremap <C-w> <C-w><C-w>"}}} | |
" Autogroup vimrcEx {{{1 | |
augroup vimrcEx | |
autocmd! | |
"autocmd BufWritePost * call system("ctags -R") | |
" Rainbow Parenthesis | |
au VimEnter * RainbowParenthesesToggle | |
au Syntax * RainbowParenthesesLoadRound | |
au Syntax * RainbowParenthesesLoadSquare | |
au Syntax * RainbowParenthesesLoadBraces | |
" highlight the status bar when in insert mode | |
if version >= 700 | |
au InsertEnter * hi StatusLine ctermfg=235 ctermbg=2 | |
au InsertLeave * hi StatusLine ctermbg=240 ctermfg=12 | |
endif | |
" highlight trailing spaces in annoying red | |
highlight ExtraWhitespace ctermbg=1 guibg=red | |
match ExtraWhitespace /\s\+$/ | |
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/ | |
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/ | |
autocmd InsertLeave * match ExtraWhitespace /\s\+$/ | |
autocmd BufWinLeave * call clearmatches() | |
autocmd User fugitive | |
\ if fugitive#buffer().type() =~# '^\%(tree\|blob\)$' | | |
\ nnoremap <buffer> .. :edit %:h<CR> | | |
\ endif | |
autocmd BufReadPost fugitive://* set bufhidden=delete | |
" When editing a file, always jump to the last known cursor position. | |
" Don't do it for commit messages, when the position is invalid, or when | |
" inside an event handler (happens when dropping a file on gvim). | |
autocmd BufReadPost * | |
\ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") | | |
\ exe "normal g`\"" | | |
\ endif | |
" Cucumber navigation commands | |
autocmd User Rails Rnavcommand step features/step_definitions -glob=**/* -suffix=_steps.rb | |
autocmd User Rails Rnavcommand config config -glob=**/* -suffix=.rb -default=routes | |
" Set syntax highlighting for specific file types | |
autocmd BufRead,BufNewFile Appraisals,.pryrc set filetype=ruby syntax=ruby | |
autocmd BufRead,BufNewFile *.{txt,mdown,markdown,md} set filetype=markdown nolist wrap linebreak | |
" Automatically source $MYVIMRC | |
autocmd BufWritePost $MYVIMRC source $MYVIMRC | |
" Set foldmethod for $MYVIMRC | |
autocmd BufRead .vimrc set foldmethod=marker | |
autocmd BufRead .vimrc set foldlevel=0 | |
" Set foldmethod for .yml/.yaml files | |
autocmd BufRead *.y{aml,ml} set foldmethod=indent foldlevel=1 | |
" Settings for Brewfile, Caskfile, etc. | |
autocmd BufRead *file set foldmethod=indent foldlevel=0 syntax=sh | |
" Set foldmethod for Rakefiles | |
autocmd BufRead *Rakefile set syntax=ruby | |
" Settings for Rspec files | |
autocmd BufRead *spec.rb set foldmethod=indent foldlevel=1 | |
" Enable spellchecking for Markdown | |
autocmd FileType markdown,text setlocal spell textwidth=78 | |
" Strip trailing whitespace on save | |
autocmd BufRead,BufWritePre *.{rb,coffee,js,sh,html,haml,sass,erb,css} :call Preserve("%s/\\s\\+$//e") | |
augroup END | |
" Functions {{{1 | |
" Highlight the match in red {{{2 | |
function! HLNext (blinktime) | |
let [bufnum, lnum, col, off] = getpos('.') | |
let matchlen = strlen(matchstr(strpart(getline('.'),col-1),@/)) let | |
target_pat = '\c\%#'.@/ | |
let ring = matchadd('WhiteOnRed', target_pat, 101) | |
redraw | |
exec 'sleep ' . float2nr(a:blinktime * 1000) . 'm' | |
call matchdelete(ring) | |
redraw | |
endfunction | |
" InsertTabWrapper function {{{2 | |
function! InsertTabWrapper() | |
let col = col('.') - 1 | |
if !col || getline('.')[col - 1] !~ '\k' | |
return "\<tab>" | |
else | |
return "\<C-p>" | |
endif | |
endfunction | |
"inoremap <Tab> <C-r>=InsertTabWrapper()<Cr> | |
" Preserve function {{{2 | |
function! Preserve(command) | |
" Preparation: save last search, and cursor position. | |
let _s=@/ | |
let l = line(".") | |
let c = col(".") | |
" Do the business: | |
execute a:command | |
" Clean up: restore previous search history, and cursor position | |
let @/=_s | |
call cursor(l, c) | |
endfunction | |
nmap _$ :call Preserve("%s/\\s\\+$//e")<CR> | |
"nmap _= :call Preserve("normal gg=G")<CR> | |
" Align function {{{2 | |
function! s:align() | |
let p = '^\s*|\s.*\s|\s*$' | |
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p) | |
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g')) | |
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*')) | |
Tabularize/|/l1 | |
normal! 0 | |
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.')) | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment