Skip to content

Instantly share code, notes, and snippets.

@mwise
Created August 15, 2013 16:05
Show Gist options
  • Save mwise/6242072 to your computer and use it in GitHub Desktop.
Save mwise/6242072 to your computer and use it in GitHub Desktop.
nnoremap <leader>ls :OpenSpecInSplit<cr>
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment