lambdalisue / jupyter-vim-binding

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

Ctrl+C to leave insert mode but copy still in visual mode #118

Open danijar opened 7 years ago

danijar commented 7 years ago

Is this possible? I played around with the code a bit. What I tried is to assign a key handler to Ctrl+C and inside that check whether the user is currently in insert mode. In insert mode, it should leave insert mode. Otherwise, I tried to return false to get the default copying behavior, but this didn't work.

Update: More generally it would be cool to be able to configure different keybindings for different modes.

flxai commented 5 years ago

I face the same problem and recognize <Ctrl-c> as vim's default shortcut to leave insert mode. To actually manually map <Ctrl-c> to <Esc> I tried the following two variations within a cell:

:imap <Ctrl-c> <Esc>
:imap <C-c> <Esc>

Unfortunately this does not work. I had no problems mapping other Ctrl shortcuts like :imap <C-o> <Esc>. I'm not quite sure how intertwined Jupyter's cells are with IPython's interactive console, because I was able to bind <Ctrl-c> within IPython.

How were you able to leave insert mode through <Ctrl-c> @danijar ?

ianhi commented 4 years ago

I think this may be possible using the codemirror map commands https://codemirror.net/doc/manual.html#vimapi but @flxai if you ran those commands from inside a cell there may be some strangeness in how codemirror handles them due to how the extrakeys are being set https://github.com/lambdalisue/jupyter-vim-binding/blob/c9822c753b6acad8b1084086d218eb4ce69950e9/vim_binding.js#L70-L74