jupyterlab-contrib / jupyterlab-vim

Vim notebook cell bindings for JupyterLab
https://jupyterlab-contrib.github.io/jupyterlab-vim.html
MIT License
660 stars 43 forks source link

Using Ctrl-enter to render Markdown cells #120

Closed SamLau95 closed 7 months ago

SamLau95 commented 9 months ago

Thanks for working on jupyterlab-vim! I'm using it to do live-coding for my lectures at UC San Diego.

My muscle memory for using ctrl-enter to render Markdown cells is quite strong. Is there a way to re-enable that command when the extension is active?

When I'm editing a Markdown cell (in vim normal or insert mode), I'd like the ability to press ctrl-enter to render the cell and return to Jupyter vim mode.

firai commented 9 months ago

It's possible to add the ability to render Markdown on Ctrl+Enter when the plugin is active, but it's currently not possible to stay in vim (Normal) mode when that happens. This is because rendering Markdown essentially turns the cell into output, and the plugin is currently not able to navigate output via vim (see #53 and #56). You can see this in action if the first cell is a Markdown cell and if you press k there (#52). Therefore, if we implement this, Ctrl+Enter in a Markdown cell would render the Markdown and then have to eject the user to Jupyter Command mode.

By the way, you may already be aware of this, but navigating up or down away from a Markdown cell in this plugin auto-renders the cell.

SamLau95 commented 9 months ago

@firai Thanks for the context. I mixed up the terminology in my original question – I'd like it if Ctrl+Enter in a Markdown cell would render Markdown and eject the user to Jupyter Command mode, as you said. From what I know, this is the default behavior of Ctrl+Enter in Jupyter Lab and Notebook.

firai commented 9 months ago

Contributions would be welcome. Looking at the key bindings, Ctrl+Enter is redirected to the vim:run-cell-and-edit command, which is defined here:

https://github.com/jupyterlab-contrib/jupyterlab-vim/blob/66c745edb07315f87b662b6d0be5539b5e5c70d0/src/labCommands.ts#L54-L66

I think what's needed here is to fire the notebook:run-cell command, which is JL's default command for this binding, if the cell is a Markdown cell. You should be able to test if the current cell is a Markdown cell by following this pattern:

https://github.com/jupyterlab-contrib/jupyterlab-vim/blob/66c745edb07315f87b662b6d0be5539b5e5c70d0/src/labCommands.ts#L201-L204