jwkvam/jupyterlab-vim

Ctrl-[ and Ctrl-C to exit insert mode

axelfahy opened this issue · 4 comments

In vim, Ctrl-[ is the equivalent of Esc and Ctrl-C quits insert mode. I think it would be nice to have the same behaviors in jupyterlab-vim.

Maybe implementing Ctrl-C is not a good idea since it will interfere with the copy shortcut. However, I think that Ctrl-[ won't interfere with other shortcuts.

Reference from vim documentation (https://vimhelp.org/insert.txt.html):

CTRL-[

<Esc> or CTRL-[ End insert or Replace mode, go back to Normal mode. Finish
abbreviation.
Note: If your key is hard to hit on your keyboard, train
yourself to use CTRL-[.
If Esc doesn't work and you are using a Mac, try CTRL-Esc.
Or disable Listening under Accessibility preferences.

CTRL-C

CTRL-C Quit insert mode, go back to Normal mode. Do not check for
abbreviations. Does not trigger the InsertLeave autocommand
event.

Update: Ctrl-[ seems to be working on Chrome but not on Firefox (v67.0.4), not sure why. (other browsers not tested)

Interesting I didn't realize ctrl-[ wasn't working on all platforms, I typically only use chrome. I just tried Firefox and it seems like it was working for me? I check Safari and it was working there for me as well.

I'm using Firefox 68.0 (Quantum) and jupyterlab-vim 0.11.0.

Maybe it is a plugin that is capturing the key, but when I use CTRL-[, it leaves the cell instead of going to normal mode (which is annoying since I have to re-click on the cell to have the focus again).

However, if I add the keybinding in src/index.ts (as in PR #86), it works as expected.

Using Firefox 68.0.1, jupyterlab 1.0.2, jupyterlab-vim 0.11.0

@llinfeng seems to have the same issue since he said in #81 that he recompiled the plugin with CTRL-[ added in the keybindings.

@axelfahy Were you also recompiling the plugin when you "added the keybindings in src/index.ts"? I am interested to learn a better way to simplify the following steps:

  1. Pull all the sources from Github,
  2. Insert my snippets of mappings to src\index.ts
        commands.addKeyBinding({
            selector: '.jp-Notebook.jp-mod-editMode',
            keys: ['Ctrl ['],
            command: 'leave-insert-mode'
        });
        commands.addKeyBinding({
            selector: '.jp-Notebook.jp-mod-editMode',
            keys: ['Ctrl ]'],
            command: 'notebook:enter-command-mode'
        });
  1. Compile by installing the dependencies and issuing the following commands as mentioned in the ReadMe
jlpm install
jlpm run build
jupyter labextension link .

I have compared things side-by-side across Chrome, Edge and Firefox

  • Ctrl + [ is working with all three browsers, per its newly mapped function of exiting from Insert mode to normal mode within the "editing cell";
  • Ctrl + ] is not working in Firefox, but working well in Chrome and Edge. When it is working, Ctrl + ] did get me out of the "editing cell" to manipulate all other cells in the notebook.

Raw conclusion: something is wrong with Firefox :) May need further debugging to see what captures Ctrl + ].

Yes, I recompiled the plugin after adding the keybinding. Afterwards, CTRL-[ worked fine.
I followed the same steps to compile the plugin, I haven't found a simpler way to do it.