alternate.vim 941 B

1234567891011121314151617181920212223242526272829303132
  1. " By default use edit (current buffer view) to switch
  2. if !exists("g:go_alternate_mode")
  3. let g:go_alternate_mode = "edit"
  4. endif
  5. " Test alternates between the implementation of code and the test code.
  6. function! go#alternate#Switch(bang, cmd) abort
  7. let file = expand('%')
  8. if empty(file)
  9. call go#util#EchoError("no buffer name")
  10. return
  11. elseif file =~# '^\f\+_test\.go$'
  12. let l:root = split(file, '_test.go$')[0]
  13. let l:alt_file = l:root . ".go"
  14. elseif file =~# '^\f\+\.go$'
  15. let l:root = split(file, ".go$")[0]
  16. let l:alt_file = l:root . '_test.go'
  17. else
  18. call go#util#EchoError("not a go file")
  19. return
  20. endif
  21. if !filereadable(alt_file) && !bufexists(alt_file) && !a:bang
  22. call go#util#EchoError("couldn't find ".alt_file)
  23. return
  24. elseif empty(a:cmd)
  25. execute ":" . g:go_alternate_mode . " " . alt_file
  26. else
  27. execute ":" . a:cmd . " " . alt_file
  28. endif
  29. endfunction
  30. " vim: sw=2 ts=2 et