How to navigate b/w cells in Google Colab when using vim editor setting?

Viewed 1302

In google colab "default" editor key binding I can move up/down the cell by hit esc and then use j or k. But if i use "vim" as key binding when I enter esc it only exits to normal mode and j and k only allow me to navigate text in the current cell.

How can I move focus up or down to other cells under "vim" key bindings?

To reproduce: in Google Colab window enter Ctrl + M + H go to preferences and select "Editor key bindings" to "Vim". Then go back try to use j and k to move up or down. the cursor will be restricted only in the current cell.

3 Answers

To focus next/previous cell with vim keybindings, do the following:

esc Leave edit mode

Ctrl + m, n Select next cell

Ctrl + m, p Select previous cell

Note: you need to release the Ctrl key when pressing n or p in the above sequences.

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.

You can set your own keyboard shortcuts in Colab.

Go to Tools ⮕ Keyboard Shortcuts and change Next cell and Previous cell to whatever you want.

I like Alt/Option + j and Alt/Option + k, respectively, since it is analogous to Vim's j and k meaning "go down one line" and "go up one line" respectively.

Ctrl + j and Ctrl + k do not seem to work as expected if you set them as the Next cell and Previous cell keys because Vim captures those commands to delete text, at least in my Colab.

Related