Vim Jupyter
Vim where VSCodeVim stops short in Jupyter
notebooks. Requires VSCodeVim. (Formerly published as Vim Notebook.)
What it adds
Jumps across cells. gd then Ctrl-O / Ctrl-I return to the exact
word, even when the definition is in another cell. VS Code's history only
restores the cell; VSCodeVim's jumplist loses track between cells.
Vim keys on a selected cell (cell selected, not being edited, where
VSCodeVim sees no key):
| Keys |
Does |
: |
Command line in the status bar: w q wq x q! wa qa wqa noh |
§ |
Search the whole notebook (see below) |
u / Ctrl-R |
Undo / redo notebook edits |
Ctrl-W h j k l / w W / s v / q o |
Move between panes, split, close, instead of closing the notebook |
| Your VSCodeVim mappings |
, ; <leader>… mappings that run commands |
A lone / outside a cell is held back (Jupyter's a would insert a cell);
inside a cell / stays Vim's own search of that cell.
Notebook search with §, from a cell or not: matches highlighted live as
you type (code and rendered markdown), Vim's match 2 of 7 after Enter,
n / N across cells (a code cell is entered with the cursor on the word),
Enter or :noh to end (Escape too, outside a cell).
Fast start. It activates first and wakes VSCodeVim, so Vim keys work as
soon as the window is up, and Ctrl-W never closes the notebook before Vim
runs.
Settings
| Setting |
Default |
|
vimNotebook.searchSymbol |
§ |
Symbol shown on the search line |
vimNotebook.doubleSlashSearch |
false |
Also search the notebook with // |
vimNotebook.stayInCell |
true |
j on a cell's last line and k on its first stay in the cell |
vimNotebook.commandLine |
statusBar |
visibleCell: run : in a code cell already on screen, with Vim's real command line |
vimNotebook.keyboardLayout |
qwerty |
azerty translates the digit row and punctuation on the : / § lines |
To use another key than §: Keyboard Shortcuts → "Vim Jupyter: Search the
Notebook". With "keyboard.dispatch": "keyCode", § on AZERTY is read as
shift+oem_8.
Wiring the jumps
settings.json:
"vim.normalModeKeyBindingsNonRecursive": [
{ "before": ["g", "d"], "commands": ["vimNotebook.goToDefinition"] }
]
keybindings.json:
{ "key": "ctrl+o", "command": "vimNotebook.back", "when": "editorTextFocus && vim.active && vim.mode == 'Normal' && vimNotebook.canGoBack" },
{ "key": "ctrl+i", "command": "vimNotebook.forward", "when": "editorTextFocus && vim.active && vim.mode == 'Normal' && vimNotebook.canGoForward" }
Typing lag with VSCodeVim
VSCodeVim handles every character typed in Insert mode itself, one round trip
after another: a key held down keeps writing for a second or two after it is
released. Each release here ships vscodevim-1.32.4-fast-insert.vsix,
VSCodeVim 1.32.4 with that fixed: once an insertion has started, characters and
Backspace go straight to the editor. u, . and the cursor behave as before.
Install it over VSCodeVim, then reload the window:
curl -LO https://github.com/typefor56/vim-jupyter/releases/latest/download/vscodevim-1.32.4-fast-insert.vsix
code --install-extension vscodevim-1.32.4-fast-insert.vsix --force
# once more for each other profile you use:
code --install-extension vscodevim-1.32.4-fast-insert.vsix --force --profile "My Profile"
To go back: code --install-extension vscodevim.vim@1.32.4 --force.
An extension installed from a .vsix is not auto-updated, so the fix stays;
Settings Sync, on the other hand, installs the Marketplace VSCodeVim on a new
machine, so run the commands above there too. To build the package yourself
from the VSCodeVim you have installed:
python3 tools/vscodevim-fast-insert.py ~/.vscode/extensions/vscodevim.vim-1.32.4 --vsix vscodevim-1.32.4-fast-insert.vsix
Measured with real key presses in a notebook cell, on a virtual display (80
repeats of a key at 50 per second): text kept coming 1.6–2.1 s after release
with VSCodeVim, 0.5 s with the fix, 0 s without any Vim. Fifteen editing
scenarios (arrows, Enter, brackets, cw then ., undo, counts, Visual…) give
the same text and cursor as the unpatched VSCodeVim. The fix steps aside when
Insert-mode mappings are configured, while a macro is recorded and with several
cursors, and the tool refuses any other VSCodeVim build.
Known limits
- VSCodeVim only redraws its status bar on a key: the
: / § line sits next
to -- NORMAL -- instead of replacing it.
- VSCodeVim binds
g h j k l o G on lists; to type them on the : / § line,
bind them to vimNotebook.exKey in keybindings.json (user bindings win),
e.g. { "key": "j", "command": "vimNotebook.exKey", "args": "j", "when": "notebookEditorFocused && !inputFocus && vimNotebook.cmdline" }.
- On other layouts with
keyCode dispatch, find how a key is read with
Developer: Toggle Keyboard Shortcuts Troubleshooting.
Build and test
npm install
npm run package # vim-jupyter-<version>.vsix
code --install-extension vim-jupyter-*.vsix
npm test # real VS Code + your VSCodeVim (VSCODE_VERSION to pick one)
MIT licence.