このvim wikiaエントリに従って、新しいバッファースクリプトへのシェル実行を作成し、それを拡張して、nodeを使用してコードを実行できます。
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
function! s:RunShellCommand(cmdline)
let isfirst = 1
let words = []
for word in split(a:cmdline)
if isfirst
let isfirst = 0 " don't change first word (shell command)
else
if word[0] =~ '\v[%#<]'
let word = expand(word)
endif
let word = shellescape(word, 1)
endif
call add(words, word)
endfor
let expanded_cmdline = join(words)
botright new
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
call setline(1, 'You entered: ' . a:cmdline)
call setline(2, 'Expanded to: ' . expanded_cmdline)
call append(line('$'), substitute(getline(2), '.', '=', 'g'))
silent execute '$read !'. expanded_cmdline
1
endfunction
command! -complete=file -nargs=* RunJS call s:RunShellCommand('node '.<q-args>)
次に、実行:RunJS %
すると、node.js実行の出力を含む新しいバッファーが取得されます。オプションで、次のものを使用して直接呼び出すことができます:Shell <cmd>
:!node %
ます。これは外部node
プログラムにシェルアウトし、現在のファイル名を引数として渡します。画面に出力が表示され、Enterキーを押して閉じることができます。