embed node.js in vim?


One thing that can make large vim scripting projects easier is its embedded interpreter support. There’s an --enable-rubyinterp flag that is included in the official builds for MacPorts, and used by janus.

Is there a way to embed node.js in vim?

Problem courtesy of: Ben Atkin


From the question I assume you want an embedded interpreter with which to directly script vim as one can do with Perl, Python, Ruby, Tcl, Scheme and Lua — so, for example, you could write vim functions in Python in your .vimrc, or so you can write a plugin in Ruby. This is different from using vim to launch external programs written in node.js, and it is different from using vim (and various third-party plugins) to help you write programs in node.js.

These embedded interfaces are hard-coded in the vim source and at this time there is no comparable embedded support for node.js, nor is there a general run-time mechanism for embedding an arbitrary interpreter. (There may be hacky workarounds in the vein of the ConqueTerm plugin, async libraries, etc.)

If you want to check for yourself and see what is currently supported in this way, you can check out the current code by using these instructions: http://www.vim.org/mercurial.php. Look for references to languages in the Makefile (I see “Perl, Python, Python3, TCL, Ruby, MZscheme, Lua”). Look under the src/ directory for files matching the glob if_*.c — my results are as follows: if_cscope.c, if_lua.c, if_mzsch.c, if_perlsfio.c, if_python3.c, if_python.c, if_ruby.c, if_sniff.c, if_tcl.c, if_xcmdsrv.c (several of these are external tools with special interfaces, rather than embedded interpreters).

If you need embedded node.js support in vim then you will probably have to write it yourself. If you do not need to actually write vim plugins using JavaScript, there is probably a better way to meet your needs.

Solution courtesy of: Sasha

View additional discussion.