lambdalisue / jupyter-vim-binding

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

Using :q to exit into Jupyter Mode #116

Closed alihaiderismail closed 6 years ago

alihaiderismail commented 6 years ago

As scanny mentioned in Evaluate Markdown #60, I think it would be a good idea to have :q be an alias for shift-esc. That is, it would serve as another way to exit into Jupyter mode.

I think in general this might be useful because it is easier to input than shift-esc. I also use the vimfx plugin in firefox which allows for vim bindings in general web browsing (not unlike vimperator). I generally have it disabled on jupyter notebooks so that I can use jupyter-vim-binding. Unfortunately it also uses shift-escape to reenable the plugin when it is disabled which leads to some conflicts.

I also personally like to use Jupyter Mode more frequently. Particularly because of the following:

So by using :q it makes going between the different modes much smoother.

I'll add a snippet to the customization wiki that I think addresses this. Here it is reproduced below. I am not too familiar with javascript so please feel free to remove unnecessary parts or fix up the syntax where appropriate.

require([
    'base/js/namespace',
    'codemirror/keymap/vim',
    'nbextensions/vim_binding/vim_binding'
], function(ns) {
    CodeMirror.Vim.defineEx("quit", "q", function(cm){
        ns.notebook.command_mode();
        ns.notebook.focus_cell();
    });
});
jwkvam commented 6 years ago

It makes going between cells easier because in Jupyter mode j,k moves between cells rather than lines

Do you not like ctrl-j and ctrl-k? That's what I use.

It allows you to move between markdown cells quicker because they do not "de-render". I edit markdown cells less frequently than code cells so I would rather not de-render them each time I pass over them.

I wrote #85 to address this which re-renders markdown cells when you leave them (under certain keystrokes). I see your point though.

alihaiderismail commented 6 years ago

Aaah, I had completely forgotten about ctrl-j and ctrl-k. That does work quite well.

In reference to your PR, I do agree that if the markdown cell is de-rendered it should be re-rendered when you leave the cell. But I find that when switching between cells, I generally don't want the markdown cells to be de-rendered in the first place.

As it currently is, when I switch between cells using j,k or ctrl-j, ctrl-k jupyter will hang for a split second as it de-renders the markdown cell and then re-renders it as I leave the cell. I find that slightly annoying. I was thinking about making a separate feature request to address that, but don't know how that would fit in properly with the theme of the plugin.

It makes sense that while in vim mode you would want to be able to move over the text in a markdown cell which is why the current functionality exists. If say it didn't work that way, when the user wants to edit the text of a markdown cell, he/she would have to press a key to de-render the cell and then another key to go into insert mode. That would be weird I would think. That's why I thought this may be a useful work around (especially considering it wasn't too hard to implement).

lambdalisue commented 6 years ago

I totally have forgot about :q idea. Thanks for making an issue. Actually I like that idea and I feel :q should be an official way to leave the Vim mode.

lambdalisue commented 6 years ago

Implemented. https://github.com/lambdalisue/jupyter-vim-binding/commit/3aefafb157d37258a587c574126d578cbd69af17