1
0
Fork 0
mirror of synced 2024-12-22 15:08:57 -05:00
ultimate-vim/sources_non_forked/vim-go/autoload/go/alternate.vim

33 lines
941 B
VimL
Raw Normal View History

2016-02-20 08:13:10 -05:00
" By default use edit (current buffer view) to switch
if !exists("g:go_alternate_mode")
let g:go_alternate_mode = "edit"
endif
" Test alternates between the implementation of code and the test code.
2016-12-27 09:46:49 -05:00
function! go#alternate#Switch(bang, cmd) abort
2016-03-14 06:04:57 -04:00
let file = expand('%')
if empty(file)
call go#util#EchoError("no buffer name")
2016-02-20 08:13:10 -05:00
return
2016-03-14 06:04:57 -04:00
elseif file =~# '^\f\+_test\.go$'
let l:root = split(file, '_test.go$')[0]
let l:alt_file = l:root . ".go"
elseif file =~# '^\f\+\.go$'
let l:root = split(file, ".go$")[0]
let l:alt_file = l:root . '_test.go'
2016-02-20 08:13:10 -05:00
else
2016-03-14 06:04:57 -04:00
call go#util#EchoError("not a go file")
return
2016-02-20 08:13:10 -05:00
endif
2016-03-14 06:04:57 -04:00
if !filereadable(alt_file) && !bufexists(alt_file) && !a:bang
call go#util#EchoError("couldn't find ".alt_file)
return
elseif empty(a:cmd)
execute ":" . g:go_alternate_mode . " " . alt_file
2016-02-20 08:13:10 -05:00
else
2016-03-14 06:04:57 -04:00
execute ":" . a:cmd . " " . alt_file
2016-02-20 08:13:10 -05:00
endif
endfunction
2016-06-26 07:12:36 -04:00
" vim: sw=2 ts=2 et