通过此vim wikia条目,您可以对新的缓冲区脚本创建shell执行,然后将其扩展为使用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键将其关闭。