let mapleader="," """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " PLUGINS """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" call pathogen#infect() call pathogen#helptags() " ctrlp.vim Config set runtimepath^=~/.vim/bundle/ctrlp.vim let g:ctrlp_map = 'ff' let g:ctrlp_cmd = 'CtrlP' let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$' map fr :call ShowRoutes() map fv :CtrlP app/views map fc :CtrlP app/controllers map fm :CtrlP app/models map fh :CtrlP app/helpers map fl :CtrlP lib map fp :CtrlP vendor/plugins map fs :CtrlP spec map ft :CtrlP test map fa :CtrlP app/assets map fj :CtrlP app/assets/javascripts nnoremap fr :ClearCtrlPCache\|:CtrlP " # gist-vim let g:gist_detect_filetype = 1 let g:gist_open_browser_after_post = 1 let g:gist_show_privates = 1 let g:gist_post_private = 1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " BASIC EDITING CONFIGURATION """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set nocompatible " allow unsaved background buffers and remember marks/undo for them set hidden set history=10000 set expandtab set tabstop=2 set shiftwidth=2 set softtabstop=2 set autoindent set laststatus=2 set showmatch set incsearch set dictionary+=/usr/share/dict/words set number set hlsearch " make searches case-sensitive only if they contain upper-case characters set ignorecase smartcase " highlight current line set cmdheight=2 set switchbuf=useopen set numberwidth=5 set showtabline=2 set winwidth=79 set shell=bash " Prevent Vim from clobbering the scrollback buffer. See " http://www.shallowsky.com/linux/noaltscreen.html set t_ti= t_te= " keep more context when scrolling off the end of a buffer set scrolloff=3 " Store temporary files in a central spot set backup set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp " allow backspacing over everything in insert mode set backspace=indent,eol,start " display incomplete commands set showcmd " Enable highlighting for syntax syntax on " Enable file type detection. " Use the default filetype settings, so that mail gets 'tw' set to 72, " 'cindent' is on in C files, etc. " Also load indent files, to automatically do language-dependent indenting. filetype plugin indent on " use emacs-style tab completion when selecting files, etc set wildmode=longest,list colorscheme Monokai set wildignore+=*/tmp/*,*/log/*,*.so,*.swp,*.zip,*/rdoc/* set colorcolumn=90 " Show trailing whitespace set list listchars=tab:»·,trail:· " Adding this since the esc remap on the 'i' key had a long delay when pressed set timeoutlen=300 ttimeoutlen=0 " When loading text files, wrap them and don't split up words. au BufNewFile,BufRead *.txt setlocal wrap au BufNewFile,BufRead *.txt setlocal lbr " Fix vim's background colour erase - http://snk.tuxfamily.org/log/vim-256color-bce.html if &term =~ '256color' " Disable Background Color Erase (BCE) so that color schemes " work properly when Vim is used inside tmux and GNU screen. " See also http://snk.tuxfamily.org/log/vim-256color-bce.html set t_ut= endif " Notes and other helpers map bb :!bundle install map gs :Gstatus map gw :!git add . && git commit -m 'WIP' && git push map nn :sp ~/Dropbox/notes/programming-notes map p :set pasteo"*]p:set nopaste map pn :sp ~/Dropbox/notes/project-notes " Remove trailing whitespace on save all files. au BufWritePre * :%s/\s\+$//e """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " CUSTOM AUTOCMDS """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" augroup vimrcEx " Clear all autocmds in the group autocmd! autocmd FileType text setlocal textwidth=78 " Jump to last cursor position unless it's invalid or in an event handler autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass,cucumber set ai sw=2 sts=2 et autocmd FileType python set sw=2 sts=2 et " Indent p tags autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif augroup END """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " STATUS LINE """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" :set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%) """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " MISC KEY MAPS """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " insert an end tag with imap end " insert a hash rocket with imap => " Mapping ESC in insert mode and command mode to double i " imap ii "" cmap ii " suspend process nmap z " Quickly edit/reload the vimrc file nmap ev :vsp $MYVIMRC nmap rv :so $MYVIMRC " remap saving and quiting :P nmap w :w nmap q :q nmap Q :q! nmap x :x :ca Wa wa :ca WA wa :ca WQ wq :ca Wq wq :ca W w :ca Q q command! Q q " Bind :Q to :q command! Qall qall " Disable Ex mode map Q " Map ctrl-movement keys to window switching map map map map " Window splitting - couldn't figure out how to remap v & n to " & map m :vsplit map mm :split map gg :topleft 100 :split Gemfile map gr :topleft 100 :split config/routes.rb " Clear the search buffer (highlighting) when hitting return function! MapCR() nnoremap :nohlsearch endfunction call MapCR() nnoremap """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " ABBREVIATIONS """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" :ab teh the """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " MULTIPURPOSE TAB KEY """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" function! InsertTabWrapper() let col = col('.') - 1 if !col || getline('.')[col - 1] !~ '\k' return "\" else return "\" endif endfunction inoremap =InsertTabWrapper() inoremap """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " RENAME CURRENT FILE """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" function! RenameFile() let old_name = expand('%') let new_name = input('New file name: ', expand('%'), 'file') if new_name != '' && new_name != old_name exec ':saveas ' . new_name exec ':silent !rm ' . old_name redraw! endif endfunction map n :call RenameFile() """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " GREP SEARCH """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" function! Search() let term = input('Grep search term: ') if term != '' exec 'Ag "' . term . '"' endif endfunction map s :call Search() """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " PROMOTE VARIABLE TO RSPEC LET """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" function! PromoteToLet() :normal! dd " :exec '?^\s*it\>' :normal! P :.s/\(\w\+\) = \(.*\)$/let(:\1) { \2 }/ :normal == endfunction :command! PromoteToLet :call PromoteToLet() :map pp :PromoteToLet """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " SWITCH BETWEEN TEST AND PRODUCTION CODE """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" function! OpenTestAlternate() let new_file = AlternateForCurrentFile() exec ':e ' . new_file endfunction function! AlternateForCurrentFile() let current_file = expand("%") let new_file = current_file let in_spec = match(current_file, '^spec/') != -1 let going_to_spec = !in_spec let in_app = match(current_file, '\') != -1 || match(current_file, '\') != -1 || match(current_file, '\') != -1 || match(current_file, '\') != -1 if going_to_spec if in_app let new_file = substitute(new_file, '^app/', '', '') end let new_file = substitute(new_file, '\.rb$', '_spec.rb', '') let new_file = 'spec/' . new_file else let new_file = substitute(new_file, '_spec\.rb$', '.rb', '') let new_file = substitute(new_file, '^spec/', '', '') if in_app let new_file = 'app/' . new_file end endif return new_file endfunction nnoremap o :call OpenTestAlternate() """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " RUNNING TESTS """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" map t :call RunTestFile() map T :call RunNearestTest() map a :call RunTests('') map c :w\|:!script/features 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\)$') != -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 . " -b") endfunction function! SetTestFile() " Set the spec file that tests will be run for. let t:grb_test_file=@% endfunction function! RunTests(filename) " Write the file and run tests for the given filename :w :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo if match(a:filename, '\.feature$') != -1 exec ":!script/features " . a:filename else if filereadable("script/test") exec ":!script/test " . a:filename elseif filereadable("Gemfile") exec ":!bundle exec rspec --color " . a:filename else exec ":!rspec --color " . a:filename end end endfunction