Jupyter Notebook + Vim/Neovim
Vim/Neovim code editing experience for Jupyter.

Overview
For data science projects, normally I use Jupyter with vim bindings. In some of the previous articles, I also mentioned several plugins which integrate with Jupyter but the experience is not quite what I am looking for.
In this article, let’s explore several possible ways that we can truly use Jupyter with Vim/Neovim code editing experience.
Table of Content
· Overview · Table of Content · Jupyter Ascending ∘ Install Jupyter Ascending ∘ Create a Notebook and Python File ∘ Vim Plugin ∘ Start Jupyter Notebook ∘ Testing · Firenvim + Jupyter ∘ Plugin ∘ Browser Addon ∘ Testing · Magma ∘ Installation ∘ Testing · Console based Plugins · Other Plugins
Jupyter Ascending
Jupyter Ascending lets you edit Jupyter notebooks from your favorite editor, then instantly sync and execute that code in the Jupyter notebook running in your browser.
Install Jupyter Ascending
Run this command to install Jupyter Ascending and the extensions.
pip install jupyter_ascending && \
jupyter nbextension install jupyter_ascending --sys-prefix --py && \
jupyter nbextension enable jupyter_ascending --sys-prefix --py && \
jupyter serverextension enable jupyter_ascending --sys-prefix --pyValidate the installation status.
jupyter nbextension list
jupyter serverextension list
Create a Notebook and Python File
Now let’s create a notebook and the corresponding Python file.
python -m jupyter_ascending.scripts.make_pair --base 01_data_prep
In my case, I create a notebook called 01_data_prep.sync.ipynb and Python file called 01_data_prep.sync.py.
Vim Plugin
Install the Vim plugin for Jupyter Ascending. In my case, I install it using packer.nvim.
use { "untitled-ai/jupyter_ascending.vim" }Start Jupyter Notebook
Start the Jupyter notebook instance.
jupyter notebook 01_data_prep.sync.ipynb

Testing
From within Vim/Neovim, I use #%% marker to separate the cells. By default, the following mappings are defined.
nmap <space><space>x <Plug>JupyterExecute
nmap <space><space>X <Plug>JupyterExecuteAll
Compared to other plugins which use a console or terminal-based approach, now you still have the notebook with the output. However, this plugin does not support JupyterLab currently.
On the contrary, if you prefer a notebook-based approach, check out nbdev.
Firenvim + Jupyter
I mentioned Firenvim in a previous article. Firenvim turns the browser into a Neovim client.
Plugin
Install the plugin using packer.nvim.
use {
"glacambre/firenvim",
run = function()
vim.fn["firenvim#install"](0)
end,
}Browser Addon
Depending on your browser, you need to install the Firefox or Chromium-based browser add-on.
Testing
Start JupyterLab and start to have fun!

- Click on any text area and it will be immediately replaced by an instance of Firenvim.
- To set the content of the now hidden text area to the content of the Neovim instance, simply
:w. If you want to close the Firenvim overlay and return to the text area, use:qor:x. If you selected an element where you expected the Firenvim frame to appear and it didn't, try pressing<C-e>. - Tips: Use
set lines=80andset columns=100to have a larger frame for editing.
Magma
In the previous 2 approaches,
- we need the Jupyter notebook instance running
- we still have the advantage of having the notebook with the output
Magma-nvim is taking a different approach. It uses Jupyter Client to communicate with the Jupyter kernel.
Installation
This plugin works in Linux since it requires certain dependencies to be installed, e.g. ueberzug.
pynvim (for the Remote Plugin API)jupyter_client (for interacting with Jupyter)ueberzug (for displaying images)Pillow (also for displaying images, should be installed withueberzug)cairosvg (for displaying SVG images)pnglatex (for displaying TeX formulas)plotlyandkaleido(for displaying Plotly figures)
I use packer.nvim to install the plugin.
use { 'dccsillag/magma-nvim', run = ':UpdateRemotePlugins' }Testing
With the plugin installed, now I can interact with a Jupyter kernel interactively from within Neovim.

Console based Plugins
There are other plugins that take a console or terminal-based approach, e.g. jupyter-vim, vim-slime, iron.nvim, sniprun or neoterm. Check out the following articles!
Other Plugins
Every developer has his or her unique development workflow and preferences. Here is a non-comprehensive list of other plugins you can explore to see if they fit your requirements. They integrate either with Juptyer or Python REPL.
VSCode so far has the best-integrated development experience with Jupyter. With Neovim's extensibility using Lua, we should expect better integration between Jupyter and Neovim in the future.
If you are not a Medium member yet and want to become one, click here. (A part of your subscription fee will be used to support alpha2phi.)






