Created
August 6, 2013 09:34
-
-
Save tcrayford/6163125 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
set nocompatible | |
filetype off | |
silent! call pathogen#runtime_append_all_bundles() | |
silent! call pathogen#helptags() | |
filetype plugin indent on | |
runtime macros/matchit.vim | |
set hidden | |
set autoread | |
set nobackup | |
set noswapfile | |
set nowritebackup | |
set number | |
set ignorecase | |
set smartcase | |
set cmdheight=2 | |
set t_Co=256 | |
let mapleader = " " | |
map <leader>r :r <C-R>=expand("%:h")<cr>/ | |
map <leader>e :e <C-R>=expand("%:h")<cr>/ | |
" Go to previous file | |
nnoremap <leader><leader> <c-^> | |
nmap <silent> <leader>v :tabe $MYVIMRC<CR> | |
" Copy current visual selection to osx clipboard | |
map <silent> <leader>y :<C-u>silent '<,'>w !pbcopy<CR> | |
map <silent> <leader>p :<C-u>silent r !pbpaste<CR> | |
map <leader>n :cn <CR> | |
map <leader>p :cp <CR> | |
nnoremap j gj | |
nnoremap k gk | |
"Seriously, guys. It's not like :W is bound to anything anyway. | |
command! W :w | |
command! Q :q | |
command! Wall :wall | |
cnoremap %% <C-R>=expand('%:h').'/'<cr> | |
" allow backspacing over everything in insert mode | |
set backspace=indent,eol,start | |
set history=1000 " keep 1000 lines of command line history | |
set ruler " show the cursor position all the time | |
set showcmd " display incomplete commands | |
set incsearch " do incremental searching | |
" Make tab completion for files/buffers act like bash | |
set wildmenu | |
set completeopt=longest,menu | |
" Softtabs, 2 spaces | |
set tabstop=2 | |
set shiftwidth=2 | |
set expandtab | |
set softtabstop=2 | |
set smarttab | |
set hlsearch | |
set cursorline | |
set numberwidth=5 | |
syntax enable | |
colorscheme solarized | |
set background=light | |
if has("autocmd") | |
augroup vimrcEx | |
au! | |
" When editing a file, always jump to the last known cursor position. | |
" Don't do it when the position is invalid or when inside an event handler | |
" (happens when dropping a file on gvim). | |
autocmd BufReadPost * | |
\ if line("'\"") > 0 && line("'\"") <= line("$") | | |
\ exe "normal g`\"" | | |
\ endif | |
augroup END | |
else | |
set autoindent " always set autoindenting on | |
endif | |
" Remap the tab key to do autocompletion or indentation depending on the | |
" context (from http://www.vim.org/tips/tip.php?tip_id=102) | |
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> | |
:set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%) | |
set laststatus=2 | |
" Map keys to go to specific files | |
function! ShowRoutes() | |
" Requires 'scratch' plugin | |
:topleft 100 :split __Routes__ | |
" Make sure Vim doesn't write __Routes__ as a file | |
:set buftype=nofile | |
" Delete everything | |
:normal 1GdG | |
" Put routes output in buffer | |
:0r! rake -s routes | |
" Size window to number of lines (1 plus rake output length) | |
:exec ":normal " . line("$") . _ " | |
" Move cursor to bottom | |
:normal 1GG | |
" Delete empty trailing line | |
:normal dd | |
endfunction | |
function! MapCR() | |
nnoremap <cr> :nohlsearch<cr> | |
endfunction | |
call MapCR() | |
" Leave the return key alone when in command line windows, since it's used | |
" to run commands there. | |
autocmd! CmdwinEnter * :unmap <cr> | |
autocmd! CmdwinLeave * :call MapCR() | |
"autocmd BufWinEnter quickfix :unmap <CR> | |
"autocmd BufWinLeave quickfix :call MapCR() | |
" Ensure vim always runs from a shell, rvm needs this. | |
set shell=/bin/sh | |
:inoremap <c-c> | |
set winwidth=84 | |
set scrolloff=2 | |
set shiftround | |
function! RunTests(filename) | |
" Write the file and run tests for the given filename | |
:w | |
if match(expand("%"), '\.clj$') != -1 | |
:echo "(midje.repl/load-facts '" . a:filename . ")" | |
:echo "\n" | |
exec ":Eval (do (require \'midje.repl)(midje.repl/load-facts '" . a:filename . "))" | |
elseif match(a:filename, '\.feature$') != -1 | |
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo | |
exec ":!bundle exec cucumber " . a:filename | |
elseif match(a:filename, '\.coffee$') != -1 | |
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo | |
exec "!jasmine-headless-webkit " . a.filename | |
else | |
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo | |
if filereadable("script/test") | |
exec ":!script/test " . a:filename | |
else | |
exec ":!bundle exec rspec " . a:filename | |
end | |
end | |
endfunction | |
function! CurrentNamespace() | |
redir => res | |
exec ":Eval (ns-name *ns*)" | |
redir END | |
return res | |
endfunction | |
function! SetTestFile() | |
" Set the spec file that tests will be run for. | |
if match(expand("%"), '\.clj$') != -1 | |
let t:grb_test_file= substitute(CurrentNamespace(), "\n", "", "g") | |
else | |
let t:grb_test_file=@% | |
endif | |
endfunction | |
function! RunTestFile(...) | |
if a:0 | |
let command_suffix = a:1 | |
else | |
let command_suffix = "" | |
endif | |
" Run the tests for the previously-marked file. | |
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|.*test.*.clj\|Spec.js\|.*Spec.*.hs\|.*Test.*hs\)$') != -1 | |
if in_test_file | |
call SetTestFile() | |
elseif !exists("t:grb_test_file") | |
return | |
end | |
call RunTests(t:grb_test_file . command_suffix) | |
endfunction | |
function! RunNearestTest() | |
let spec_line_number = line('.') | |
call RunTestFile(":" . spec_line_number) | |
endfunction | |
map <leader>d :redraw!<cr> | |
" Test running on leader | |
map <leader>t :call RunTestFile()<cr> | |
map ; :call RunTestFile()<cr> | |
map <leader>T :call RunNearestTest()<cr> | |
map <leader>a :call RunTests('')<cr> | |
map <leader>w :w\|:!script/wip<cr> | |
map <leader>c :w\|:!script/features<cr> | |
map <leader>C :w\|:!script/features --profile wip<cr> | |
map <leader>R :w\|:!ruby %<cr> | |
map <leader>l :w\|:!script/lint %<cr> | |
map <leader>L :w\|:!script/lint<cr> | |
map <leader>gt :w\|:!script/tags<cr> | |
"jumping to files on leader | |
map <leader>gr :topleft :split config/routes.rb<cr> | |
map <leader>gR :call ShowRoutes()<cr> | |
map <leader>gq :CommandTFlush<cr>\|:CommandT app/estately<cr> | |
map <leader>gv :CommandTFlush<cr>\|:CommandT app/views<cr> | |
map <leader>gc :CommandTFlush<cr>\|:CommandT app/controllers<cr> | |
map <leader>gm :CommandTFlush<cr>\|:CommandT app/models<cr> | |
map <leader>gn :CommandTFlush<cr>\|:CommandT mlses<cr> | |
map <leader>ge :CommandTFlush<cr>\|:CommandT app/mailers<cr> | |
map <leader>gh :CommandTFlush<cr>\|:CommandT app/helpers<cr> | |
map <leader>gl :CommandTFlush<cr>\|:CommandT lib<cr> | |
map <leader>go :CommandTFlush<cr>\|:CommandT app/observers<cr> | |
map <leader>gj :CommandTFlush<cr>\|:CommandT app/assets/javascripts/js<cr> | |
map <leader>gp :CommandTFlush<cr>\|:CommandT public<cr> | |
map <leader>gs :CommandTFlush<cr>\|:CommandT app/assets/stylesheets/<cr> | |
map <leader>gf :CommandTFlush<cr>\|:CommandT features<cr> | |
map <leader>gg :topleft 100 :split Gemfile<cr> | |
map <leader>ga :CommandTFlush<cr>\|:CommandT app/assets<cr> | |
map <leader>f :CommandTFlush<cr>\|:CommandT<cr> | |
map <leader>F :CommandTFlush<cr>\|:CommandT %%<cr> | |
map <leader>sq :CommandTFlush<cr>\|:CommandT spec/estately<cr> | |
map <leader>sv :CommandTFlush<cr>\|:CommandT spec/views<cr> | |
map <leader>sc :CommandTFlush<cr>\|:CommandT spec/controllers<cr> | |
map <leader>sm :CommandTFlush<cr>\|:CommandT spec/models<cr> | |
map <leader>sn :CommandTFlush<cr>\|:CommandT spec/mlses<cr> | |
map <leader>se :CommandTFlush<cr>\|:CommandT spec/mailers<cr> | |
map <leader>sh :CommandTFlush<cr>\|:CommandT spec/helpers<cr> | |
map <leader>sl :CommandTFlush<cr>\|:CommandT spec/lib<cr> | |
map <leader>so :CommandTFlush<cr>\|:CommandT spec/observers<cr> | |
imap <c-l> <space>=><space> | |
imap <c-j> <space>-><space> | |
imap <c-h> <space><-<space> | |
imap <c-k> <%<space><space>%><esc>F<space>i | |
function! WritingText() | |
:set spell | |
:map <leader>a :normal gqap<cr> | |
:map <leader>j :call FormatJava()<cr> | |
:set tabstop=4 | |
:set shiftwidth=4 | |
:set softtabstop=4 | |
:map <leader>s :w\|!texcount *.tex *.latex<cr> | |
endfunction | |
function! BuildSurvey() | |
:w | |
:!sh script/build | |
:!open report.pdf | |
endfunction | |
let Tlist_Use_Right_Window = 1 | |
set wildignore+=*.o,*.obj,.git,*.pyc,*.log,*.rbc,*.hi,vendor/*,kafka/*,_darcs/*,dist/*,target/* | |
autocmd! BufReadPost *.latex :call WritingText() | |
autocmd! BufReadPost *.tex :call WritingText() | |
autocmd! BufReadPost *.md :call WritingText() | |
autocmd! BufReadPost *.markdown :call WritingText() | |
autocmd! BufReadPost *.latex :map <leader>t :call BuildSurvey()<cr> | |
autocmd! BufReadPost *.md :map <buffer><leader>t :w\|!open "%"<cr> | |
autocmd! bufwritepost .vimrc source ~/.vimrc | |
" ignore latex files | |
set wildignore+=*.bbl,*-blx.bib,*.aux,*.log,*.pdf,*.pdf,*.blg,*.out,*.xml,*.toc | |
let g:Tex_DefaultTargetFormat = 'pdf' | |
let g:Tex_ViewRule_pdf = 'Preview' | |
let Tex_FoldedSections="" | |
let Tex_FoldedEnvironments="" | |
let Tex_FoldedMisc="" | |
" stop jumping around by char | |
"map <Left> :echo "no!"<cr> | |
"map <Right> :echo "no!"<cr> | |
"map <Up> :echo "no!"<cr> | |
"map <Down> :echo "no!"<cr> | |
"indentation inside html tags | |
autocmd TabEnter,WinEnter,BufWinEnter *.html,*.erb let g:html_indent_tags = g:html_indent_tags.'\|p' | |
autocmd! InsertLeave,CursorMoved *.sass,*.erb,*.coffee,*.js,*.css :w | |
set showtabline=2 | |
set autoread | |
set t_ti= t_te= | |
" No delay before hitting O straight after | |
set noesckeys | |
let vimclojure#WantNailgun = 0 | |
let vimclojure#NailgunClient = "ng" | |
let vimclojure#SplitSize = 8 | |
let vimclojure#UseErrorBuffer = 0 | |
let vimclojure#FuzzyIndent=1 | |
let g:vimclojure#ParenRainbow=1 | |
let vimclojure#HighlightBuiltins=1 | |
let vimclojure#ParenRainbowColors = { | |
\ '0': 'ctermfg=237', | |
\ '1': 'ctermfg=237', | |
\ '2': 'ctermfg=237', | |
\ '3': 'ctermfg=237', | |
\ '4': 'ctermfg=237', | |
\ '5': 'ctermfg=237', | |
\ '6': 'ctermfg=237', | |
\ '7': 'ctermfg=237', | |
\ '8': 'ctermfg=237', | |
\ '9': 'ctermfg=237', | |
\ } | |
" use ghc functionality for haskell files | |
" au Bufenter *.hs compiler ghc | |
" Configure browser for haskell_doc.vim | |
let g:haddock_browser = "open" | |
let g:haddock_browser_callformat = "%s %s" | |
inoremap <C-f> <c-r>=InsertTabWrapper()<cr> | |
let g:syntastic_enable_highlighting=1 | |
highlight ExtraWhitespace ctermbg=red guibg=red | |
au ColorScheme * highlight ExtraWhitespace guibg=red | |
au BufEnter * match ExtraWhitespace /\s\+$/ | |
au InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/ | |
au InsertLeave * match ExtraWhiteSpace /\s\+$/ | |
let g:hdevtools_options = '-g-isrc -g-Wall -g-fno-warn-unused-do-bind -g-fno-warn-type-defaults -g-fno-warn-orphans' | |
let g:ackprg = 'ag --nogroup --nocolor --column' | |
let g:syntastic_javascript_jshint_conf = "--config ~/.jshint" | |
let g:paredit_shortmaps=0 | |
let g:gitgutter_enabled = 0 | |
map <leader>to :GitGutterToggle<cr> | |
map <leader>tj :w\|:silent !git aa %<cr> | |
function! KillFileAndBuffer() | |
:silent !rm -f % | |
:bd! | |
endfunction | |
map <leader>tk :call KillFileAndBuffer()<cr> | |
function! ReloadChrome() | |
execute 'silent !osascript ' . | |
\'-e "tell application \"Google Chrome\" " ' . | |
\'-e "repeat with i from 1 to (count every window)" ' . | |
\'-e "tell active tab of window i" ' . | |
\'-e "reload" ' . | |
\'-e "end tell" ' . | |
\'-e "end repeat" ' . | |
\'-e "end tell" >/dev/null' | |
endfunction | |
nnoremap <leader>o :call ReloadChrome()<CR>:pwd<cr> | |
" Fix slow O inserts | |
:set timeout timeoutlen=1000 ttimeoutlen=100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment