Google colaboratory is an amazing tool and the only thing that keeps me from using it more often is the absence of vim keybindings. Is there a way to enable it just like its possible to do for jupyter notebooks and jupyter lab?
My solution: in "keyboard preferences" I set ^ + j to "Next cell" and ^ + k to "Previous cell". You can also just use the default key bindings but I personally found it easier this way.
It's now available in google colab by default. You can select Vim keybindings from Tools > Settings > Editor, or by typing Ctrl+M H
Here is a little hack to enable Vim mode via the JavaScript console. Annoyingly, it needs to be re-run each time a cell is executed, so I've bound ctrl/cmd-enter
and shift-enter
to do just that:
function enable_vim() { document.querySelectorAll(".CodeMirror").forEach(function (e) { e.CodeMirror.setOption("vimMode", true); }); }
document.addEventListener('keydown', function(e) {
if (e.keyCode == 13 && e.metaKey || e.keyCode == 13 && e.shiftKey) {
for (var i = 0; i < 10; i++) setTimeout(enable_vim, 1000 * i);
}
});
enable_vim();
Just be careful to be in normal mode (not in input mode) when running a cell. Otherwise Vim mode will be permanently disabled for that cell and one needs to reload the entire web app to re-enable it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With