-
-
Notifications
You must be signed in to change notification settings - Fork 138
Custom bindings for <Esc> #8
Comments
Im sorry but if CodeMirror's mapping didnot work, i hava no idea. While this use CodeMirror's Vim mode, asking it in that repository might give you hint i guess. let me know if you manage. |
and i'm sure there is a way while CodeMirror could do it :-) |
I will, thanks a lot! km.command_shortcuts.add_shortcut('ctrl-enter', 'ipython.execute-in-place'); |
They answered quite fast, here is the solution: var exports = {
'load_ipython_extension': function() {
// apply options and events on existing CodeMirror instances
namespace.notebook.get_cells().map(function(cell) {
var cm = cell.code_mirror;
var map = {'J K': leaveInsertOrNormal,
'Esc': leaveInsertOrNormal,
'Tab': insertSoftTab,
};
CodeMirror.normalizeKeyMap(map);
if (cm) {
cm.setOption('keyMap', 'vim');
cm.setOption('extraKeys', map);
cm.on('blur', leaveInsert);
}
});
}
};
return exports; |
It seems useful. I'll add that :-) You probably need to add 'J K' mapping to https://github.com/lambdalisue/jupyter-vim-binding/blob/master/nbextensions/vim_binding.js#L52-L55 as well. |
Hi @gboehl did this actually work for you? |
Well, afterwards you won't be able to use 'J' anymore because he's waiting for the 'K', so the answer ist rather "No". :) To get this working one would have to get deeper into how key bindings are dealt with in CodeMirror, and I unfortunately don't have the time for that. But if you have a solution, let me know! |
What I actually did was add this line to
somewhere around line 66 under default keymap, just duplicated the line above that was mapping
|
Great plugin btw lambdalisue - thanks! |
😄 |
Actually @gboehl there's an even easier and better way, without modifying vim.js, just put this somewhere in vim_binding.js:
It maps any key to any key, e.g. I also have for instance:
|
Both solutions work just fine, thanks a lot! |
Probably using custom.js is better I guess |
@lambdalisue TODO Document this conversations to README |
Thanks guys. I finally add it to the document (use |
👍 |
I have a similar problem, I want to map Esc in normal mode to go to command mode, this is what I tried var leaveNormalOrInsertMode = function (cm) {
var command = CodeMirror.Vim.findKey(cm, "<Esc>"); // <--- I don't know what this does
//console.log(command, cm.state.vim.normalMode,cm.state.vim.insertMode,cm.state.vim);
if (typeof command === 'function') {
return command();
}else{
if (!(cm && cm.state.vim.insertMode)){
CodeMirror.prototype.leaveNormalMode(cm);
}
}
}
cm_config.extraKeys = $.extend(cm_config.extraKeys || {}, {
//'Esc': CodeMirror.prototype.leaveInsertMode,
'Esc': leaveNormalOrInsertMode,
'Shift-Esc': CodeMirror.prototype.leaveNormalMode,
'Ctrl-C': false, // To enable clipboard copy
}); I guess there might be an issue that you didn't do it yourself by default. if you could give me a hint where the problem is, I'll appreciate it |
This worked for me : https://gist.github.com/m4nuC/01b02ce6feac6dcda14d0323729b709f |
Do you just add this line, or are there other things to be done? Where in vim_bindings.js should this line be added? Just adding it does not seem to work for me. |
Thanks a lot for your excellent work!
I was wondering if there is the chance to allow for multi-stroke bindings (f.e. "j,j" or "j,k") to be mapped against . I only managed to map normal key presses by replacing 'Esc' in the last paragraph...
Would you have any hints?
The text was updated successfully, but these errors were encountered: