Skip to content

Instantly share code, notes, and snippets.

@davidmfoley
Created February 11, 2011 01:11
Show Gist options
  • Save davidmfoley/821746 to your computer and use it in GitHub Desktop.
Save davidmfoley/821746 to your computer and use it in GitHub Desktop.
.vimrc hack to add rspec and jasmine navigation to/from spec (app, javascript, etc)
function! FindOrCreateAlternate()
let buflist = []
let bufcount = bufnr("$")
let currbufnr = 1
let current = fnamemodify(expand("%"), ':p')
if current =~ '/spec/'
if current =~ '/spec/javascripts/'
let altname = substitute(current, "/spec/","/public/", 'g')
let altname = substitute(altname, "\Spec.js", ".js",'g')
else
let altname = substitute(current, "/spec/","/app/", 'g')
let altname = substitute(altname, "\_spec.rb", ".rb",'g')
endif
else
if current =~ '/javascripts/'
let altname = substitute(current, "/public/","/spec/", 'g')
let altname = substitute(altname, ".js", "Spec.js", 'g')
else
let altname = substitute(current, "/app/","/spec/", 'g')
let altname = substitute(altname, ".rb", "_spec.rb", 'g')
endif
endif
while currbufnr <= bufcount
if(buflisted(currbufnr))
let currbufname = bufname(currbufnr)
let curmatch = tolower(currbufname)
if(altname == currbufname)
call add(buflist, currbufnr)
endif
endif
let currbufnr = currbufnr + 1
endwhile
if(len(buflist) > 1)
exec ":b " . get(buflist,0)
else
:w
exec ":e " . altname
endif
endfunction
function! TestToggleNewTabVertical()
:vsplit
call FindOrCreateAlternate()
endfunction
function! TestToggleNewTabHorizontal()
:split
call FindOrCreateAlternate()
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment