Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

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

Open
danijar opened this issue Nov 4, 2017 · 2 comments
Open

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

danijar opened this issue Nov 4, 2017 · 2 comments

Comments

@danijar
Copy link

danijar commented Nov 4, 2017

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
Copy link

flxai commented Sep 9, 2019

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
Copy link

ianhi commented Jul 27, 2020

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

cm_config.extraKeys = $.extend(cm_config.extraKeys || {}, {
'Esc': CodeMirror.prototype.leaveInsertMode,
'Shift-Esc': CodeMirror.prototype.leaveNormalMode,
'Ctrl-C': false, // To enable clipboard copy
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@danijar @ianhi @flxai and others