Skip to content
Javascript runtime library in vim, it use PyV8 as interpreter, and aslo create a browser-based context to execute javascript code
Python VimL JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

jsruntime.vim (Run javascript code directly in Vim)

It use PyV8 as javascript interpreter. if PyV8 not supported, it use node, cscript, spiderMonkey as fallbacks.


Copy everything inside autoload to autoload directory of your vim


It is a basic library. It does nothing if no other plugin calls it. If you are a vim plugin developer and want to use this library. You need to check if this library exist

        call javascript#runtime#evalScript("")
        let jsruntimePluginAvailable = 1
    catch E117
        let jsruntimePluginAvailable = 0

    if jsruntimePluginAvailable
        " your code

This library is often used with jsoncodecs.vim.



It provide the following functions

  1. javascript#runtime#evalScript({script}, {renew_context})

    :echo javascript#runtime#evalScript('1+2')
    // output 3

    renew_context is a flag to indicate whether keep the context created by script before

    :call javascript#runtime#evalScript('a=3')  // we create a context
    :echo javascript#runtime#evalScript('a;') // we eval this script in context created before
    // output 1
    :echo javascript#runtime#evalScript('a;',1) // we eval this script in a completely new context
    // output undefined

    renew_context is not guaranteed support, if not support renew_context will be simply ignored, please

    read javascript#runtime#supportLivingContext for more.

  2. javascript#runtime#evalScriptInBrowserContext

    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('javascript#runtime#evalScriptInBrowserContext')
        // do what you like


    :call javascript#runtime#evalScriptInBrowserContext('<html><body onload="console.log(1+2);"><p></p></body></html>')
    //output 3
  3. javascript#runtime#isSupportLivingContext

    you can use javascript#runtime#isSupportLivingContext to check whether living_context is supported by jsruntime

Something went wrong with that request. Please try again.