lambdalisue / jupyter-vim-binding

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

Shortcut to enter jupyter mode from Vim command/editing mode #74

Open shichao116 opened 8 years ago

shichao116 commented 8 years ago

Hi all,

The short cut from Vim command mode to jupyter command mode is Shift-Escape by default. It's pretty awkward key binding. Can I modify it?

Thanks.

lambdalisue commented 8 years ago

Why do you need to be in Jupyter mode? I'm asking that because most of operation can be perform in Vim's command mode.

scanny commented 8 years ago

One reason would be to preview a Markdown cell, say to make sure a LaTex expression formatted the way you intended.

Right now what I do for that is press Shift-Enter, but that moves you down to a next cell (creating one if necessary).

This isn't a problem for, say Python cells, because you can run them and stay in Vim mode. But if you want to run a Markdown cell it requires you be in Jupyter command mode as far as I can tell.

For my use case, if Cmd-Enter ran a Markdown cell and placed the cell into Jupyter command mode, that would do the trick. I'd happily press Enter (or 'i') when I was done to get back into Vim command mode when I was done inspecting the rendering.

Let me know if this really becomes a separate issue/enhancement proposal (to make Cmd-Enter on Markdown cells put you into Jupyter command mode); I'm happy to start a separate issue for it if that's a help :)

Also, if there's a quick configuration routine I can place in the custom.js, I'd be happy to do that too, just let me know :)

Thanks for jupyter-vim-binding, btw; it's really a fabulous thing to have Vim in the notebook :)

dabro commented 8 years ago

Also Shift-Esc interferes with Vimperator. I would love to figure out how to make awesome Jupyter-vim-binding work more compatibly with Vimperator. So at that point there are three layers: vim-bindings, Jupyter, and Vimperator.

It is possible to go from Vimperator directly to vim-binding ('i' puts you in Vimperator insert mode), but 'ESC' misses normal mode and goes back to Vimperator. 'Shift-ESC' temporarily kills Vimperator, allowing you to use vim-binding normal mode, but then swallows the Shift-ESC that gets you back in Vimperator mode, which means jumping to another tab to get back into Vimperator.

lambdalisue commented 8 years ago

@scanny I have totally forgot about this but I'll change the behaviour of Cmd-Enter to stay in Jupyter mode. https://github.com/lambdalisue/jupyter-vim-binding/issues/60

@dabro This plugin is not designed for using with Vimperator. I use vimperator as well but I disabled it on jupyter.

chuaxr commented 7 years ago

I often restart the kernel and run all cells. Currently, I do so by mapping a shortcut in jupyter mode (Shift-R), and so have to press the somewhat awkward combination of Shift-Esc Shift-R. The ability to either change the Shift-Esc shortcut or add my own shortcut to vim-jupyter would therefore be helpful.

lambdalisue commented 7 years ago

https://github.com/lambdalisue/jupyter-vim-binding/blob/master/lib/jupyter/shortcuts.js#L89

Does this help?

If not, I recommend you to map that to C-o,C-r in edit mode shortcut so that you don't have to escape to jupyter mode. See a bit below of the above link

chuaxr commented 7 years ago

Re your first comment: the pre-existing shortcut doesn't restart the kernel.

Re your second comment: I was able to add a mapping to $(jupyter --data-dir)/nbextensions/vim_binding/lib/jupyter/shortcuts.js and it works, thanks!

joelostblom commented 7 years ago

@shichao116 If you still wish to modify the shortcut, you can do so by editing ~/.local/share/jupyter/nbextensions/vim_binding/vim_binding.js (or wherever you installed it).

At line 72, I changed

'Shift-Esc': CodeMirror.prototype.leaveNormalMode,

to

'Alt-Esc': CodeMirror.prototype.leaveNormalMode,

which is easier to type for me since the right thumb can reach Alt.