Permalink
Browse files

update vimrc

  • Loading branch information...
1 parent f921b3c commit 66d74e29cfa24c228ab669209f6c4e9a3b1f08ee @therod committed Apr 16, 2012
Showing with 34 additions and 0 deletions.
  1. +34 −0 vim/vimrc.symlink
View
@@ -83,6 +83,10 @@ augroup vimrcEx
" Don't syntax highlight markdown because it's often wrong
autocmd! FileType mkd setlocal syn=off
+
+ " Velocity
+ autocmd! BufRead,BufNewFile *.vm set filetype=velocity
+
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@@ -178,6 +182,36 @@ map <leader>gt :CommandTFlush<cr>\|:CommandTTag<cr>
map <leader>f :CommandTFlush<cr>\|:CommandT<cr>
map <leader>F :CommandTFlush<cr>\|:CommandT %%<cr>
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" 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, '\<controllers\>') != -1 || match(current_file, '\<models\>') != -1 || match(current_file, '\<views\>') != -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 <leader>. :call OpenTestAlternate()<cr>
+
" ----------------------------------------------------------------------------
" STATUS LINE
" ----------------------------------------------------------------------------

0 comments on commit 66d74e2

Please sign in to comment.