Last active
August 29, 2015 14:04
-
-
Save mwise/b6154f942ce566471983 to your computer and use it in GitHub Desktop.
Vim function to open spec in split
This file contains 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
fun! OpenFilesInSplit(left, right) | |
if a:left == a:right | |
return | |
endif | |
only | |
exec "edit " . a:left | |
exec "vs " . a:right | |
execute "normal! \<c-w>t" | |
endfun | |
fun! OpenSpecInSplit() | |
let file = expand('%:p') | |
if match(file, "app/") >= 0 | |
if match(file, "assets/javascripts") >= 0 | |
let f1 = substitute(file, "\\.js\.coffee", ".spec.coffee", "") | |
let f2 = substitute(f1, "app\/assets\/javascripts\\/", "spec/javascripts/spec/", "") | |
else | |
let f1 = substitute(file, "\\.rb", "_spec.rb", "") | |
let f2 = substitute(f1, "app\\/", "spec/", "") | |
endif | |
call OpenFilesInSplit(f2, file) | |
exec "w" | |
else | |
if match(file, "spec/") >= 0 | |
if match(file, "spec/javascripts") >= 0 | |
let f1 = substitute(file, "\.spec\.coffee", ".js.coffee", "") | |
let f2 = substitute(f1, "spec/javascripts/spec", "app/assets/javascripts", "") | |
else | |
let f1 = substitute(file, "\_spec", "", "") | |
let f2 = substitute(f1, "spec/", "app/", "") | |
endif | |
call OpenFilesInSplit(file, f2) | |
exec "w" | |
endif | |
endif | |
endfun | |
com! OpenSpecInSplit :call OpenSpecInSplit() | |
nnoremap <leader>ls :OpenSpecInSplit<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment