jupyterlab_vim
adds a truly unfortunate keybinding where, if you are in normal mode and press -
, the current cell splits into two.
I have never intentionally activated this feature yet have unintentionally activated it many dozens of times. It's awful.
Unfortunately, the logical route to disable the split-cell feature (modifying keybinding config files) doesn't work. I don't know why.
Therefore, I now manually locate the vim_bindings file and patch it:
#!/usr/bin/env python3
from pathlib import Path
from jupyter_core.paths import jupyter_path
SPLIT_CELL_SNIPPET = """this._commands.execute("notebook:split-cell-at-cursor")"""
DISABLED_SPLIT_CELL_SNIPPET = f"/*{SPLIT_CELL_SNIPPET}*/"
lab_ext_dir = Path(jupyter_path("labextensions")[0])
assert lab_ext_dir.exists(), f"{lab_ext_dir}?"
vim_ext_dir = lab_ext_dir / "@axlair/jupyterlab_vim/static"
assert vim_ext_dir.exists() and len(list(vim_ext_dir.glob("*.js"))) > 0, f"{vim_ext_dir}?"
print(f"\033[40m\033[97m \u2315 Found vim extension directory \033[0m")
for js_path in vim_ext_dir.glob("*.js"):
with js_path.open() as js_file: js_contents = js_file.read()
if SPLIT_CELL_SNIPPET not in js_contents or DISABLED_SPLIT_CELL_SNIPPET in js_contents: continue
with js_path.open("w") as js_file: js_file.write(js_contents.replace(SPLIT_CELL_SNIPPET, DISABLED_SPLIT_CELL_SNIPPET))
print("\033[42m\033[97m \u2713 Split-cell keybinding is now disabled \033[0m")
After patching the js file, reloading jupyterlab in the browser (with caches disabled) should fetch the new js file and the split-cell keybinding to -
should now be disabled.