yixin0829
yixin0829

Reputation: 109

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

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.

Upvotes: 6

Views: 3890

Answers (3)

Pog Le Pog
Pog Le Pog

Reputation: 193

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.

You can remember them by: (n)ext and (p)revious

Upvotes: 8

satvikpendem
satvikpendem

Reputation: 179

You can set your own keyboard shortcuts in Colab.

Go to ToolsKeyboard 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.

Upvotes: 1

yixin0829
yixin0829

Reputation: 109

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.

Upvotes: 2

Related Questions