Oct 24, 2011

Invoking Groovy Script Directly on Vim using quickrun.vim and GroovyServ

There is an excellent vim plugin, quickrun.vim.

It makes your trial and error cycle much faster. It makes your script edited on vim invoke by shortcut keys. It's very useful for writing a script.

The plugin supports many programming languages including Groovy. But still the original Groovy command has the weak point; the starting-up of invocation is slow. Your "flow" or "zone" is interrupted by each invocation. But now, there is GroovyServ for you. It's very easy to configure your vim to use GroovyServ's groovyclient instead of original Groovy's command. Add the following lines at .vimrc:
let g:quickrun_config = {}
let g:quickrun_config.groovy = {'command' : 'groovyclient'}
Of course, GroovyServ must be installed and groovyclient must be added into PATH environment variables.

The default key bind to run a script is <Leader>r. If you want to modify it, add the following lines:
let g:quickrun_no_default_key_mappings = 1
nmap <Leader>r <Plug>(quickrun)
In my configuration, the <Leader> is a comma. So, when I input the keys of ",r", quickrun.vim works.

If you run a script by quickrun.vim first, a groovyserver's preparation might take several seconds. The starting-up messages aren't emitted to a result buffer, so you might think it's a freeze, but it's still working.
If you invoke groovyserver explicitly before you use quickrun.vim, the first invocation of quickrun.vim will be quite fast.

BTW, there are scripts which doesn't work well with GroovyServ. If your script is so, use original Groovy command on your terminal.

Enjoy your Groovy and Vim life!

1 comment:

  1. If you are using vim 8 / neovim, maybe you can try asyncrun: https://github.com/skywind3000/asyncrun.vim as a replacement to quickrun with better user experience and expansibility.

    ReplyDelete