Overriding Default Vim-test Strategies
vim-test can help you to turn a process of running tests into pleasure. It has multiple strategies for tests execution: basic, dispatch, tmux, neovim terminal, etc. Each strategy is hardcoded inside vim-test/autoload/test/strategy.vim, but we can easily override any of them.
If you are using neovim, then you probably want to take full advantage of its
embedded terminal. By default neovim strategy for test execution will open new
terminal buffer with command enew
and start insert mode.
function! test#strategy#neovim(cmd) abort
enew | call termopen(a:cmd) | startinsert
endfunction
However, it takes over the active split and, upon test completion, the terminal and the split get closed (issue #25):
To override this strategy we need to move test#strategy#neovim
function into
.vimrc (.nvimrc) and place it right after the end of plugins initialization:
I use vim-plug and override neovim strategy for opening new horizontal split with terminal:
...
call plug#end() " plugins initialization finished
" Custom neovim strategy for vim-test
function! test#strategy#neovim(cmd) abort
botright new | call termopen(a:cmd) | startinsert
endfunction
When !
is used inside function!
definition then an existing function will
be silently replaced.
That's how overrided strategy works:
Any strategy from vim-test/autoload/test/strategy.vim can be overrided this way.
Update 2015-08-10
Vim-test now supports custom strategies. Example above can be rewritten like this:
function! SplitStrategy(cmd)
botright new | call termopen(a:cmd) | startinsert
endfunction
let g:test#custom_strategies = {'terminal_split': function('SplitStrategy')}
let g:test#strategy = 'terminal_split'