Skip to content

Instantly share code, notes, and snippets.

@user202729
Last active August 22, 2021 13:13
Show Gist options
  • Save user202729/d1446251d5653704a45873f10d69c990 to your computer and use it in GitHub Desktop.
Save user202729/d1446251d5653704a45873f10d69c990 to your computer and use it in GitHub Desktop.
Use JavaScript interactive/REPL shell with vim (like IPython + jupyter-vim)

Update: there might be a better way. Lookup "vim Node.js REPL" ("interactive shell" doesn't result in anything. The terminology is different between Python and Node.js/JavaScript)


These kernels [2] doesn't work

What is wrong with those?

  • Tab completion is broken (even though IJavaScript claims to support it)
  • When jupyter console --kernel javascript is run, when it's exited, there's a stray node process that must be killed manually)

What works?

  • Launch node manually.

How to send code to like jupyter-vim plugin for jupyter consoles

Note: this method has the disadvantage that it doesn't stop sending commands when there's an error.

function JavaScriptShellOpen()
	rightbelow vertical term node --experimental-repl-await
	call feedkeys("\<c-w>\<c-w>p")
endfunction

nnoremap <buffer> \jo :call JavaScriptShellOpen()<cr>
nnoremap <buffer> \jO :call JavaScriptShellOpen()<cr>

let s:to_last_window='<c-w><c-w>p'
" paste content of "a into the last window
let s:send_code=s:to_last_window..'<c-w>"a'..s:to_last_window

" send paragraph to node shell
exec 'nmap <buffer> \jr mb"ayip`b'..s:send_code

" send selected to node shell
exec 'vmap <buffer> \jr "ay'..s:send_code

" send line to node shell
exec 'nmap <buffer> \jl "ayy'..s:send_code

" send cell to node shell (not implemented!)
nmap <buffer> \X <nop>

Not guaranteed to work if there are more than 2 windows in the tab.

Autocomplete in vim buffer

???


2: List of all kernels: https://github.com/jupyter/jupyter/wiki/Jupyter-kernels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment