googlecolab / colabtools

Python libraries for Google Colaboratory
Apache License 2.0
2.2k stars 721 forks source link

Exit cell from vim #746

Open marskar opened 5 years ago

marskar commented 5 years ago

Bug report for Colab: http://colab.research.google.com/.

For questions about colab usage, please use stackoverflow.

katlyn-edwards commented 5 years ago

Hey! Thanks for filling feedback and using Vim mode!

Just to be super clear about the bug, is the desired end state that a shortcut (like Shift+Esc) leaves the editor, and puts focus on the cell as a whole?

You can see the different focus levels by doing the following: Loading up the welcome notebook (or any notebook), you're dropped into "cell" level focus. The editor is not shown, and up/down keys hop between cells.

Pressing "enter" will drop you into "editor" mode, where the code / markdown editor is shown.

With default keyboard shortcuts, I believe Esc will leave editor mode, and return to cell mode. With Vim, what I observe is that no such equivalent exists, thus the need for Shift+Esc.

Let me know if I'm reading into it correctly.

marskar commented 5 years ago

Yes, you are 100% correct. You described the issue much better than I ever could 😄

ZacMilano commented 5 years ago

Currently the only way I see to exit Insert mode (and go to Normal (Vim) mode) is by running an :imap <Something> <Esc> command before going into insert for the first time (but this seems to be needed after each page reload).

Something else that would be nice is to have something like a .vimrc file, or at least a memory of the commands that have been run (e.g. remappings), and mappings such as :nnoremap <A> <B> (non-recursive, in the case of wanting to switch the functionality of two keymappings).

ddalex commented 4 years ago

@ZacMonroe I can exit Insert and move to Normal by hitting Esc. I think this issue talks about an extra mode, "cell level", which allows manipulation at cell level using the keybindings (select, move, merge, etc...). A similar 3-mode is present in Jupyter-Vim-Binding https://github.com/lambdalisue/jupyter-vim-binding

For people looking to exit to cell level in colab using the vim mode, what I do is use Ctrl-N (key binding for Next Cell, you can customize in the Ctrl-M, H panel) that takes the mode to cell level.

marskar commented 4 years ago

@ddalex, like @katlyn-edwards, you described the issue much better than I ever could 😄 In addition to Jupyter-Vim-Binding, the 3 modes (outside Vim mode, normal inside, insert inside) are also present in jupyterlab-vim. Both use Shift+Esc to exit Vim mode. Ctrl-N indeed moves me to the next cell, but it only works consistently in insert mode and I have to be in the last line in the cell and it only sometimes takes me out of Vim mode. I found out that I can also move to previous cell with Ctrl-p, but similarly it only works consistently in insert mode and I have to be in the first line in the cell and it only sometimes takes me out of Vim mode.

tcapelle commented 4 years ago

do we have a fix for this? I am loving VIM mode, bu I am unable to move out of VIM to cell mode.

maisonhai3 commented 4 years ago

Totally agree to add a way to exit focus a cell with vim mode.

While using vim, only ESC can not exit to not-in-a-cell status.

databongdata commented 4 years ago

Another vote to ask for a fix> I also cannot figure out how to exit "Normal" mode into "cell mode to navigate to different cells. If anyone knows of hack lemme know. Even using CTRL-M-A to try to add another cell automatically drops me in "Normal" mode -cheers.

RichardLee0211 commented 4 years ago

the same issue with me. Is there a short cut to move focus between cells, create new cells, and delete cells.

lun-moon commented 4 years ago

Here is a console/javascript hack to change keyboard F2 into a way to remove focus (blur) from a VIM cell in colab (if you find yourself stuck in a cell and want out, hit F2)

    function release2(e){
      if(e.keyCode == 113){
        document.activeElement.blur()
      }
    }
    document.addEventListener('keydown', release2);

reference: https://developer.mozilla.org/en-US/docs/Web/API/Document/keydown_event https://docs.cypress.io/api/commands/blur.html#Syntax

jankaifer commented 4 years ago

@lun-moon blur() didn't work for me. But this double combo works for me: ctrl+click and then arrow up. That always takes me to the cell mode.

But so far I was not able to create a JS snippet that would simulate this behavior.

@katlyn-edwards any updates?

nikisix commented 3 years ago

Shift+Esc please!

Trying to set Unfocus Current Cell to Shift+Esc manually, gives: Ignoring protected or invalid key sequence Shift+Esc.

nikisix commented 3 years ago

This is a separate issue, but in vim-mode one expects O/o for new cell above/below. Forcing Ctrl+m a/b in cell-level normal mode is monstrous.

Please see https://github.com/lambdalisue/jupyter-vim-binding for inspiration 🙏

mskar commented 3 years ago

Please see https://github.com/lambdalisue/jupyter-vim-binding for inspiration 🙏 The JupyterLab equivalent of the jupyter-vim-binding extension is https://github.com/jwkvam/jupyterlab-vim Both Jupyter extensions use Shift-Esc to go from Jupyter edit mode to Jupyter command mode.

ayhon commented 3 years ago

Another person that wants this. What I've been doing is creating a new cell either above or below and converting it to a text cell with Ctrl+M M, to avoid touching the mouse. Quite monstruous, but at least works.

yingshaoxo commented 3 years ago

This is essential for development.

Oceanbao commented 3 years ago

Just wanted to share Ctrl-M + ESC since I didn't see any mention. This enter Cell-Level mode from both Insert- or Normal-Mode, where j and k navigate cells as up and down. Maybe this is good enough as Shift-ESC but for me a simpler shortcut would be ideal. Cheers.

eliasffyksen commented 3 years ago

Quick fix notice (TLDR, read steps 1 - 3)

Hi, after trolling around in the interface for solutions, I found a quick fix.

Bad news: The problem is obviously (I think, don't quote me :) that the binding for leaving cell editing is bound to escape, which never gets triggered when you are using vim mode.

Good news: This action can be changed to some other key or key combination.

Steps for quick fix:

  1. Press Ctrl + M H (to bring up the key binding help)
  2. Find the action called Unfocus current cell (this should be bound to Esc)
  3. Change the binding to something else f.ex Ctrl + Esc (PS: Shift + Esc does not work for some reason)

The name of the action is slightly confusing since it says Unfocus current cell, but what should happen after you do this is:

Maybe a good permanent fix for this would be to just set this as the default keybinding when in vim mode.

nikisix commented 3 years ago

Anyone know where the vim-logic resides within this repo?

eduardo4jesus commented 3 years ago

I just noticed that CTRL-M + J and CTRL-M + K works just nicely. BUT, it would still be better to press some short cut to go to a cell navigation mode. Ctrl-M + ESC did not work for me.

katlyn-edwards commented 3 years ago

Anyone know where the vim-logic resides within this repo?

https://github.com/brijeshb42/monaco-vim is the library we use.

nikisix commented 3 years ago

https://github.com/brijeshb42/monaco-vim is the library we use.

Ok, created an upstream issue. LMK if it doesn't make sense. https://github.com/brijeshb42/monaco-vim/issues/88

brijeshb42 commented 3 years ago

Replied with a solution

NikkiSatmaka commented 2 years ago

Since there's already a solution from the upstream, how do we fix the issue in colab?

olmozavala commented 1 year ago

Hi, I still see the same behavior in colab. How can I apply the solution?

hrdkbhatnagar commented 1 month ago

Any idea if this has been fixed? I still cannot exit the cell from the vim keybindings

ianzhuo commented 1 month ago

A simple workaround here. Remapped Unfocus current cell action from Esc to Ctrl+M C and it worked very well.