Home

Awesome

jupyterlab-vim

Community fork of https://github.com/jwkvam/jupyterlab-vim updated for jupyterlab 2, 3 and 4

Extension status Github Actions Status Binder npm version npm downloads PyPI Conda Version

Notebook cell vim bindings

jlabvim

Modes

Like vim, Jupyterlab has a distinction between Edit mode and Command mode. Jupyterlab is in Command mode when the cursor is not in a specific cell, and it is in Edit mode when typing in a cell.

This extension combines the Jupyterlab (Edit and Command) modes with the standard vim modes (Normal, Insert and Visual). So the set of modes now looks like:

  1. Jupyterlab Command mode
  2. Jupyterlab Edit mode
    • Normal
    • Insert
    • Visual

See key bindings for switching between modes.

Install

pip install jupyterlab-vim

or with conda/mamba:

mamba install -c conda-forge jupyterlab_vim

Key Bindings

To learn how to modify key bindings see the modify-keybinds.md file.

Please note that all keys are lowercase unless <kbd>Shift</kbd> is explicitly indicated. For example, "<kbd>Y</kbd>, <kbd>Y</kbd>" means pressing lowercase <kbd>y</kbd> twice, while "<kbd>Shift-Y</kbd>, <kbd>Y</kbd>" means pressing <kbd>Shift</kbd>+<kbd>y</kbd> followed by a lowercase <kbd>y</kbd>.

Shortcuts that this extension introduces:

Vim Ex commands

CommandAction
:w[rite]Save Notebook
:q[uit]Enter Jupyter Command Mode

Vim (Jupyter Edit mode) bindings

ShortcutAction
-Split Cell at Cursor
Ctrl-O, -Split Cell at Cursor
Ctrl-Shift-JExtend Marked Cells Below
Ctrl-Shift-KExtend Marked Cells Above
Ctrl-JSelect Cell Below
Ctrl-KSelect Cell Above
Ctrl-O, GSelect First Cell
Ctrl-O, Ctrl-GSelect Last Cell
Ctrl-O, OInsert Cell Below
Ctrl-O, Ctrl-OInsert Cell Above
Ctrl-O, DDelete (Cut) Cell
Ctrl-O, YYank (Copy) Cell
Ctrl-O, PPaste Cell Below
Ctrl-EMove Cell Down
Ctrl-YMove Cell Up
Ctrl-O, UUndo Cell Action
Ctrl-O, Z, ZCenter Cell
Ctrl-GShow Tooltip
Cmd/Ctrl-1Change to Code Cell
Cmd/Ctrl-2Change to Markdown Cell
Cmd/Ctrl-3Change to Raw Cell
Shift-EscExit to Command Mode
Esc or Ctrl-[Exit Current Mode

Jupyter Command mode bindings

ShortcutAction
G, GSelect First Cell
Shift-GSelect Last Cell
OInsert Cell Below
Shift-OInsert Cell Above
D, DDelete (Cut) Cell
Y, YYank (Copy) Cell
PPaste Cell Below
Shift-PPaste Cell Above
Ctrl-EMove Cells Down
Ctrl-YMove Cells Up
UUndo Cell Action
Z, ZCenter Cell
Z, CHide Code Cell
Z, OShow Code Cell
Z, MHide All Code Cells
Z, RShow All Code Cells

Switching between modes

Special Thanks

From @jwkvam:

I want to acknowledge Alisue and his excellent work creating vim bindings for Jupyter notebooks. I hope this extension can meet the high bar his work set.

@jkwvam is the original author of this extension - the original version can be seen here. When that version was not updated it was updated first by @axelfahy and then moved to this community organization.

Contributing

Contributions and feedback are most welcome!

Development install

Note: You will need NodeJS to build the extension package. To install with conda do:

conda install -c conda-forge nodejs

The jlpm command is JupyterLab's pinned version of yarn that is installed with JupyterLab. You may use yarn or npm in lieu of jlpm below.

# Clone the repo to your local environment
# Change directory to the jupyterlab_vim directory
# Install package in development mode
pip install -e .
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Rebuild extension Typescript source after making changes
jlpm run build

You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.

# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm run watch
# Run JupyterLab in another terminal
jupyter lab

With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).

By default, the jlpm run build command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:

jupyter lab build --minimize=False

Uninstall

pip uninstall jupyterlab_vim