""" """ @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' Bundle 'leshill/vim-json' " 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 'skalnik/vim-vroom' "" "" 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 on this line map h :s/:\([a-z0-9_]\+\)\s*=>/\1: /g " Easy saving of files nnoremap Z :w nnoremap ZZ :wq "" "" 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 " Highlight certain files as Ruby au BufNewFile,BufRead *.gemfile set filetype=ruby au BufNewFile,BufRead *.rake set filetype=ruby 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! " Alternate between tabs map m :tabn map :w map s :w " Remap :W => :w to avoid errors command! W w "" "" Inline Testing "" let g:vroom_use_binstubs = 1 let g:vroom_use_colors = 1 let g:vroom_map_keys = 0 let g:vroom_spec_command = 'bundle exec rspec --format=documentation ' let g:vroom_test_unit_command = 'bundle exec ruby -Itest ' "let g:vroom_test_unit_command = 'rtest ' nnoremap t :VroomRunNearestTest nnoremap T :VroomRunTestFile 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 in_test = match(current_file, '^test/') != -1 let using_test_unit = isdirectory('./test') if using_test_unit let going_to_spec = !in_spec else let going_to_spec = !in_test endif 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 if using_test_unit let new_file = substitute(new_file, '^spec/', 'test/', '') let new_file = substitute(new_file, '_spec\.rb$', '_test.rb', '') let is_unit = match(new_file, 'models') != -1 let is_func = match(new_file, 'controllers') != -1 if is_unit let new_file = substitute(new_file, 'models', 'unit', '') endif if is_func let new_file = substitute(new_file, 'controllers', 'functional', '') endif end 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 . :call OpenTestAlternate()