Created
July 30, 2013 18:35
-
-
Save djbender/6115550 to your computer and use it in GitHub Desktop.
credit to garybernhardt put in your ~/.vimrc
This file contains hidden or 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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" 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 || match(current_file, '\<helpers\>') != -1 | |
if going_to_spec | |
if in_app | |
let new_file = substitute(new_file, '^app/', '', '') | |
end | |
let new_file = substitute(new_file, '\.e\?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 | |
let mapleader="," | |
nnoremap <leader>. :call OpenTestAlternate()<cr> | |
let mapleader="\\" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment