微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在gvim中运行javascript?

我的系统:xp g vim.
我打开g vim来编辑一个 javascript语句,该文件还没有名字.

print(sum(range(1,10)));

我想映射< F7>到javascript,如何在_vimrc中编写地图句子?
当配置完成后输入F7时,如何获得55?

我做elclanrs说,错误输出

C:\WINDOWS\system32\cmd.exe /c ( node ^<C:\DOCUME~1\sanya\LOCALS~1\Temp\VIi8C.tmp)    
[stdin]:1    
print(sum(range(1,10)));    
      ^    
ReferenceError: range is not defined    
    at [stdin]:1:11    
    at Object.<anonymous> ([stdin]-wrapper:6:22)    
    at Module._compile (module.js:456:26)    
    at evalScript (node.js:532:25)    
    at ReadStream.<anonymous> (node.js:154:11)    
    at ReadStream.EventEmitter.emit (events.js:117:20)    
    at _stream_readable.js:920:16    
    at process._tickCallback (node.js:415:13)    
shell returned 8    
Hit any key to close this window...

解决方法

在VIM中运行JavaScript的最简单方法是安装 NodeJS然后您可以使用VIM在Node中运行当前缓冲区

:w !node

你甚至不需要保存它.使用console.log:

console.log(sum(range(1,10)));

映射F7.适用于当前文件

map <F7> :call Run() <cr>
function Run()
  exec "! node %"
endfunction

要在浏览器中执行它,您只需将其编写为HTML格式的脚本:

<script>
  alert('in browser!');
</script>

并在浏览器中运行它,例如F5:

map <F5> <Esc>:silent !google-chrome %<cr>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐