2023-11-27

Jupyter Notebook Console in VIM

Jupyter currently has 3 frontends:

  1. Terminal Console (jupyter console)
  2. Qt Console (jupyter qtconsole)
  3. Notebook (jupyter notebook)

The kernel and frontend communicate over a ZeroMQ/JSON based messaging protocol, which allows multiple frontends (even of different types) communicating with a single kernel.

A Jupyter console (No. 1) is an interactive terminal that allows you to execute code, inspect variables, and use shell commands. It is connected to the Jupyter notebook’s kernel, which means that you can access the same variables and functions that are defined in the notebook. This makes it a powerful tool for debugging and testing code, as well as for exploring data interactively.

The figure below shows how to open a new interactive console from the Notebook frontend.

Deno Console

As shown in this notebook, Jupyter notebook frontend supports also Deno JavaScript kernel. This means that when you open the console, you will have a Deno JavaScript interactive environment instead of the default python kernel.

Terminal Console in VIM

To open a Jupyter console in VIM which is connected to the notebook’s python kernel run the following command (vim-floaterm plugin required):

   :FloatermNew jupyter.exe console --existing  

A possible Floaterm wrapper is shown below.

function! floaterm#wrapper#jupyterconsole#(cmd, jobopts, config) abort

  let g:floaterm_wintype = 'split'
  let g:floaterm_position = 'bottom'
  let g:floaterm_height = 0.4 
  return [v:false, 'jupyter console --existing']
endfunction

Jupytext

Additionally, as shown in the video below, you can open a Python script paired with a Jupyter notebook using Jupytext, and send a portion of the script to the Jupyter console that’s opened within the VIM terminal.

Or use the %load command that allows loading the contents from an external script. Avoid typing exit in the IPython session as it will shut down the kernel.

The notebook featured in the video can be found on this website under the IPYNB category.