""" """ @tubbo's vimrc """ "" "" Dependencies "" set rtp+=~/.vim/bundle/vundle/ call vundle#rc() Bundle 'gmarik/vundle' " Colors Bundle 'altercation/vim-colors-solarized' " Languages Bundle 'vim-ruby/vim-ruby' Bundle 'jelera/vim-javascript-syntax' Bundle 'kchmck/vim-coffee-script' Bundle 'tpope/vim-markdown' Bundle 'skwp/vim-rspec' Bundle 'tpope/vim-rails' Bundle 'sunaku/vim-ruby-shoulda-context' Bundle 'vim-scripts/nginx.vim' " Tools Bundle 'tpope/vim-fugitive' Bundle 'Lokaltog/vim-easymotion' Bundle 'rstacruz/sparkup', {'rtp': 'vim/'} Bundle 'git://git.wincent.com/command-t.git' Bundle 'Lokaltog/vim-powerline' Bundle 'scrooloose/syntastic' Bundle 'Shougo/neocomplcache' Bundle 'mattn/webapi-vim' Bundle 'mattn/gist-vim' Bundle 'vim-scripts/sudo.vim' Bundle 'janx/vim-rubytest' "" "" Basic Setup "" set nocompatible " Use vim, no vi defaults set number " Show line numbers set ruler " Show line and column number syntax enable " Turn on syntax highlighting allowing local overrides set encoding=utf-8 " Set default encoding to UTF-8 "filetype off " Somebody told me to add this I dunno. set shell=zsh " Use the greatest shell in the universe inline set autoread " Reload files after a change set showcmd " Show (partial) command in the status line set clipboard=unnamed " Use the system clipboard when possible. set laststatus=2 " Make Powerline work on single-file sessions let mapleader = "," " Set leader key to something easier to access "" "" Whitespace "" set wrap " turn word wrap on set textwidth=72 " attempt to enforce 72 chars set tabstop=2 " a tab is two spaces set shiftwidth=2 " an autoindent (with <<) is two spaces set expandtab " use spaces, not tabs set list " Show invisible characters set backspace=indent,eol,start " backspace through everything in insert mode if exists("g:enable_mvim_shift_arrow") let macvim_hig_shift_movement = 1 " mvim shift-arrow-keys endif " List chars set listchars="" " Reset the listchars set listchars=tab:\ \ " a tab should display as " ", trailing whitespace as "." set listchars+=trail:. " show trailing spaces as dots set listchars+=extends:> " The character to show in the last column when wrap is " off and the line continues beyond the right of the screen set listchars+=precedes:< " The character to show in the last column when wrap is " off and the line continues beyond the right of the screen "" "" Searching "" set hlsearch " highlight matches set incsearch " incremental searching set ignorecase " searches are case insensitive... set smartcase " ... unless they contain at least one capital letter " Search highlighting, only done by request and easy to get rid of. set nohlsearch nnoremap :set hlsearch! nnoremap :nohl "" "" Documentation "" " Ctrl+H browses, then use Ctrl+H,{N|S} to scroll through them. vmap nnoremap n :tnext nnoremap s :tselect "" "" Wild settings "" " TODO: Investigate the precise meaning of these settings " set wildmode=list:longest,list:full " Disable output and VCS files set wildignore+=*.o,*.out,*.obj,.git,*.rbc,*.rbo,*.class,.svn,*.gem " Disable archive files set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz " Ignore bundler and sass cache set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle/*,*/.sass-cache/* " Disable temp and backup files set wildignore+=*.swp,*~,._* "" "" Backup and swap files "" set backupdir=~/.vim/_backup// " where to put backup files. set directory=~/.vim/_temp// " where to put swap files. "" "" Misc. "" let macvim_hig_shift_movement = 1 " MacVim shift+arrow-keys behavior (required in .vimrc) " Skip bullshit directories let Grep_Skip_Dirs = 'RCS CVS SCCS .svn generated .sass-cache .git' set grepprg=/bin/grep\ -nH " Enforce Ruby 1.9 syntax in the selection "map h %s/:\([a-z0-9_]\+\)\s*=>/\1: /g "" "" Testing "" let g:rubytest_cmd_test = "rtest %p" let g:rubytest_cmd_testcase = "rtest %p -n \'/%c/\'" let g:rubytest_cmd_spec = "rspec --format=documentation %p" let g:rubytest_cmd_example = "rspec --format=documentation %p -l '%c'" let g:rubytest_cmd_feature = "cucumber %p" let g:rubytest_cmd_story = "cucumber %p -n '%c'" "" "" Autocommands "" augroup vimrcEx " Clear all autocmds in the group autocmd! " Jump to last cursor position unless it's invalid or in an event handler autocmd BufReadPost * \ if line("'\"") > 0 && line("'\"") <= line("$") | \ exe "normal g`\"" | \ endif " On the contrary, Haml and HTML files can be uber-long sometimes, " so we will ignore wrapping in Haml. autocmd FileType haml,html setlocal nowrap " In Ruby, autoindent with two spaces, always expand tabs autocmd FileType coffee,ruby,haml,eruby,yaml,html,javascript,sass,cucumber set ai sw=2 sts=2 et " In Python, maintain strict 4-space indents and don't word wrap autocmd FileType python set sw=4 sts=4 set wrap=off " Alternative Markdown extensions autocmd BufRead *.mkd set ai formatoptions=tcroqn2 comments=n:> textwidth=120; autocmd BufRead *.markdown set ai formatoptions=tcroqn2 comments=n:> textwidth=120; " Alternative YAML extensions autocmd BufRead *.fdoc* set filetype=yaml autocmd BufRead *.pv set filetype=yaml " Standard two-space indentation in CoffeeScript files au BufNewFile,BufReadPost *.coffee setl shiftwidth=2 expandtab " Strip whitespace in Python autocmd BufWritePre *.py :%s/\s\+$//e augroup END " When there's no text behind it, tab indents. When there is, tab " autocompletes. function! InsertTabWrapper() let col = col('.') - 1 if !col || getline('.')[col - 1] !~ '\k' return "\" else return "\" endif endfunction inoremap =InsertTabWrapper() inoremap " Opens the README.md file function! OpenReadme() if filereadable('README.md') edit README.md endif endfunction " Turn backups off since we store everything in Git set nobackup set nowb set noswapfile " Persistent undo try if MySys() == "windows" set undodir=C:\Windows\Temp else set undodir=~/.vim_runtime/undodir endif set undofile catch endtry "" "" Color Scheme "" let g:solarized_italic=0 syntax on colorscheme solarized set background=light "" "" Navigation "" " Search for files map :CommandT " Pressing ,ss will toggle and untoggle spell checking map ss :setlocal spell! " Find either the test file or implementation file path for the currently-opened file " (depending on which one it is) " Open this file's corresponding test or implementation. function! OpenTestAlternate() let new_file = AlternateForCurrentFile() exec ':e ' . new_file endfunction " Find the test or implementation code that corresponds with this file. function! AlternateForCurrentFile() let using_rspec = filereadable('spec/spec_helper.rb') let current_file = expand("%") let new_file = current_file let in_test = match(current_file, '^test/') != -1 || match(current_file, '^spec/') != -1 let going_to_test = !in_test let in_app = match(current_file, '\') != -1 || match(current_file, '\') != -1 || match(current_file, '\') != -1 || match(current_file, '\') != -1 || match(current_file, '\') != -1 || match(current_file, '\') != -1 || match(current_file, '\') != -1 || match(current_file, '\') != -1 if going_to_test if in_app let new_file = substitute(new_file, '^app/', '', '') end " Test::Unit places its tests in a different location than RSpec if using_rspec let new_file = substitute(new_file, '\.rb$', '_spec.rb', '') let new_file = 'spec/' . new_file else let new_file = substitute(new_file, '\.rb$', '_test.rb', '') let new_file = 'test/' . new_file let new_file = substitute(new_file, 'models', 'unit', '') let new_file = substitute(new_file, 'support', 'unit', '') let new_file = substitute(new_file, 'controllers', 'functional', '') endif else if in_app let new_file = 'app/' . new_file end if using_rspec let new_file = substitute(new_file, '_spec\.rb$', '.rb', '') let new_file = substitute(new_file, 'spec/', '', '') else let new_file = substitute(new_file, '_test\.rb$', '.rb', '') let new_file = substitute(new_file, '^test/', '', '') if match(new_file, 'support/') let new_file = substitute(new_file, 'unit', 'support', '') else let new_file = substitute(new_file, 'unit', 'models', '') endif let new_file = substitute(new_file, 'functional', 'controllers', '') endif endif return new_file endfunction nnoremap . :call OpenTestAlternate() map . " Remap :W => :w to avoid errors command! W w