You're right, the syntax is slightly wrong (for all of them!). If you intend to issue two :!
calls, these must be separated by |
(escaped <Bar>
in a mapping), not &&
:
autocmd FileType java nnoremap <buffer> <F9> :exec '!javac' shellescape(%) <Bar> exec '!java' shellescape(%:r)<cr>
But better do this with a single call: The &&
must then be quoted, so that it is evaluated by the shell launched by :!
, not Vim:
autocmd FileType java nnoremap <buffer> <F9> :exec '!javac' shellescape(%) '&& java' shellescape(%:r)<cr>
Furthermore, the special %
keyword is only recognized directly in the command-line, not when using it in an :execute
expression. You need to wrap this with expand()
. Oh, and shellescape()
should receive an additional flag for proper :!
escaping.
autocmd FileType java nnoremap <buffer> <F9> :exec '!javac' shellescape(expand('%'), 1) '&& java' shellescape(expand('%:r'), 1)<cr>