lambdalisue / jupyter-vim-binding

Jupyter meets Vim. Vimmer will fall in love.
2.1k stars 136 forks source link

Can't type numbers 1-6 in vim command line (:) #2

Closed annawhitney closed 9 years ago

annawhitney commented 9 years ago

When : is typed to enter the vim command line in a Jupyter notebook, any numbers entered at that point are interpreted as header levels for the first line of that cell (i.e., toggling between # FIRST LINE HERE through ###### FIRST LINE HERE), rather than actually appearing in the command line.

I'm trying to do a search-and-replace in a pair of lines changing all instances of 1 to 2, and I have no way to type 1 or 2 into the search-and-replace.

annawhitney commented 9 years ago

This also seems to happen with o and g (can't type them into the vim command line because some other behavior is triggered instead). I can work around 1-6 and o like so:

%%javascript

Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('1');
Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('2');
Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('3');
Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('4');
Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('5');
Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('6');
Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('o');

But trying to do the same for g gives me the error "Javascript error adding output! Error: trying to remove a non-existent shortcut See your browser Javascript console for more details." (and in fact I can't see any behavior being triggered by typing g, it just takes me out of the vim command line).

This workaround also means I have to give up on using o to open new cells (plus the header effects of 1-6, but I don't really care about those), so it would be nice to have a better solution.

lambdalisue commented 9 years ago

Thanks for reporting! Well I checked the code and found my silly default keybindings. These key-bindings come from Jupyter's default key-bindings and I didn't aware that the numbers would conflict with Vim's binding.

I will remove these default mappings (0 - 9) later while it should prefer to follow Vim's binding, not Jupyter's binding :smile:

lambdalisue commented 9 years ago

This also seems to happen with o and g (can't type them into the vim command line because some other behavior is triggered instead)

Hum... I didn't read this line. It sounds the things are more complicated than I thought...

lambdalisue commented 9 years ago

It seems that keys in command_shortcuts of Jupyter will be called in Vim's command mode. Which is unexpected behaviour and keys in command_shortcuts should not be called in Vim's command mode while Vim's command mode should be in Jpyter's Edit mode.

So things should be

Jupyter (Command)
  |      ^
  | (i)  | (esc)
  v      |
Jupyter (Edit)
|
|-- Vim Command (CodeMirror)
|-- Vim Normal (CodeMirror)
|-- Vim Edit (CodeMirror)
`-- Vim Virtual (CodeMirror)

But it seems

Jupyter (Command)
`-- Vim Command (CodeMirror)
  |      ^
  | (i)  | (esc)
  v      |
Jupyter (Edit)
|-- Vim Normal (CodeMirror)
|-- Vim Edit (CodeMirror)
`-- Vim Virtual (CodeMirror)

So it cannot be fixed. If you desire, you can remove shortcuts registered in here but it would make things really unconvinient.

lambdalisue commented 9 years ago

I disabled 0-6 mappings but as I explained, it cannot be fixed completely.