sponsor Vim development Vim logo Vim Book Ad

jsruntime.vim : Run javascript in vim

 script karma  Rating 19/6, Downloaded by 767    Comments, bugs, improvements  Vim wiki

created by
yf liu
script type
This is Javascript Runtime in Vim

As you know, Vim is well integrated with python,perl etc, but no javascript, that is what this plugin does.

This plugin provide the ability to integrate your Vim with javascript, It use PyV8 as javascript interpreter. if PyV8 not supported, it use node, cscript, spiderMonkey as fallbacks.

The github-repo: https://github.com/michalliu/jsruntime.vim

Use g:loaded_jsruntime to check jsruntime plugin state  

g:loaded_jsruntime doesn't exists ----------->  jsruntime plugin doesn't installed
g:loaded_jsruntime equals to 0    ------------>  jsruntime plugin is installed but not working properly
g:loaded_jsruntime equals to 1    ------------> jsruntime plugin is working

Functions registered to current buffer by jsruntime.vim

1. b:jsruntimeEvalScript({script}, {renew_context})
    renew_context is a flag to indicate whether keep the context created by script before

    :echo b:jsruntimeEvalScript('1+2')
        // output 3
    :call b:jsruntimeEvalScript('a=1')  // we create a context
    :echo b:jsruntimeEvalScript('a;') // we eval this script in context created before
        // output 1
    :echo b:jsruntimeEvalScript('a;',1) // we eval this script in new context
        // output undefined

     living context is not guaranteed to support, use b:jsruntime_support_living_context to check whether living_context is support

2. b:jsruntimeEvalScriptInBrowserContext({html_code})

    because we only implement browser interface using PyV8, so if PyV8 is not supported, this function will not exist, check existence before use

    // vim script
    if exists('b:jsruntimeEvalScriptInBrowserContext')
        // do what you like

    for example

    :call b:jsruntimeEvalScriptInBrowserContext('<html><body onload="console.log(1+2);"><p></p></body></html>')
    //output 3

List of plugins powered by jsruntime.vim
jsflakes.vim http://www.vim.org/scripts/script.php?script_id=4057
sourcebeautify.vim http://www.vim.org/scripts/script.php?script_id=4079
install details
This plugin is a bit large because it packing with PyV8 for both windows and linux to make this plugin more easy to use https://github.com/michalliu/jsruntime.vim/issues/5

You have to combine these parts after download.

Linux users      --------------->   cat jsruntime.zip.part* > jsruntime.zip
Windows users --------------->  copy /b jsruntime.zip.part* jsruntime.zip

unzip it then put  plugin/jsruntime to $VIM\plugin

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
jsruntime4.0.zip 4.0 2014-08-07 7.0 yf liu output error details when something wrong in the script to be evaluate
jsruntime3.0.zip 3 2014-05-22 7.0 yf liu fix a serious bug, will cause eval script incorrectly, detail https://github.com/michalliu/jsruntime.vim/commit/fc3c940ec90b39aa0b22aaf725198f04f6f90381

Note, if you need a binary version PyV8, You can download from the previous release
jsruntime.zip.part03 2.0 2012-05-27 7.0 yf liu part 4 of 4
the last part
jsruntime.zip.part02 2.0 2012-05-27 7.0 yf liu part 3 of 4
jsruntime.zip.part01 2.0 2012-05-27 7.0 yf liu part 2 of 4
jsruntime.zip.part00 2.0 2012-05-27 7.0 yf liu part 1 of 4
1. added linux support
2. recompile pyv8 from lastest source  for both linux and windows
3. added CJK characters support
jsruntime.zip 1.1 2012-05-11 7.0 yf liu fix python namespace confiction
jsruntime.zip 1.0 2012-05-10 7.0 yf liu repacking
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo