Home

Awesome

jupytext.vim

Vim/Neovim plugin for editing Jupyter notebook (ipynb) files through jupytext.

https://www.vim.org/scripts/script.php?script_id=5764

Installation

  1. Make sure that you have the jupytext CLI program installed (pip install jupytext).
  2. Copy the jupytext.vim script to your vim plugin directory (e.g. $HOME/.vim/plugin). Refer to :help add-plugin, :help add-global-plugin and :help runtimepath for more details about Vim plugins.
  3. Restart Vim.

Usage

When you open a Jupyter Notebook (*.ipynb) file, it is automatically converted from json to markdown or python through the jupytext utility, and the result is loaded into the buffer. Upon saving, the ipynb file is updated with any modifications.

In more detail, opening a file notebook.ipynb in vim will create a temporary file notebook.md or notebook.py (depending on g:jupytext_fmt). This file is the result of calling e.g.

jupytext --to=md --output notebook.md notebook.ipynb

jupytext.vim screenshot

The contents of the file is loaded into the buffer instead of the original notebook.ipynb. When saving the buffer, its contents is written again to notebook.md, and the original notebook.ipynb is updated with a call to

jupytext --to=ipynb --from=md --update --output notebook.ipynb notebook.md

The --update flag ensures the output for any cell whose corresponding input in notebook.md is unchanged will be preserved.

On closing the buffer, the temporary notebook.md will be deleted. If notebook.md already existed when opening notebook.ipynb, the existing file will be used (instead of being generated by jupytext), and it will be preserved when closing the buffer.

Configuration

The plugin has the following settings. If you want to override the default values shown below, you can define the corresponding variables in your ~/.vimrc.

Note: If you are using this plugin as a replacement for the ipynb_notedown.vim plugin (https://www.vim.org/scripts/script.php?script_id=5506), you can use the following options to use notedown instead of jupytext:

let g:jupytext_command = 'notedown'
let g:jupytext_fmt = 'markdown'
let g:jupytext_to_ipynb_opts = '--to=notebook'