Open tqhdesilva opened 7 years ago
I currently does not have an environment to test but does the following code helps you?
// ~/.jupyter/custom/custom.js
require([
'jquery',
'base/js/namespace',
'notebook/js/cell',
'nbextensions/vim_binding/vim_binding', // To call the function after 'vim_binding'
], function($, ns, cell, vim_binding) {
"use strict";
var Cell = cell.Cell;
// Update default config
var cm_config = Cell.options_default.cm_config;
cm_config.extraKeys = $.extend(cm_config.extraKeys || {}, {
'Ctrl-C': CodeMirror.prototype.leaveInsertMode,
});
// Update existing config
ns.notebook.get_cells().map(function(cell) {
var cm = cell.code_mirror;
if (cm) {
cm.setOption('extraKeys', $.extend(
cm.getOption('extraKeys') || {},
cm_config.extraKeys
));
}
});
});
If not, I need time to investigate...
The code above is an essence of https://github.com/lambdalisue/jupyter-vim-binding/blob/master/vim_binding.js
Ah, sorry I got the problem by reading the code. The code above won't work
https://github.com/lambdalisue/jupyter-vim-binding/blob/master/vim_binding.js#L70-L74
These lines overwrite mappings written in custom.js
.
Probably these keys should be obtained from params
here https://github.com/lambdalisue/jupyter-vim-binding/blob/master/vim_binding.js#L39-L44 so that users can modify
Currently I don't have enough time for this project. So anyone?
This is important to me. I will try to have a look to make a reasonable PR when I get the chance... In the meantime, for anyone coming here, a workaround can be to simply edit the source code of the extension (i.e. $(jupyter --data-dir)/nbextensions/vim_binding/vim_binding.js
) to read:
// ...
var cm_config = Cell.options_default.cm_config;
cm_config.keyMap = 'vim';
cm_config.extraKeys = $.extend(cm_config.extraKeys || {}, {
'Esc': CodeMirror.prototype.leaveInsertMode,
'Shift-Esc': CodeMirror.prototype.leaveNormalMode,
'Ctrl-C': CodeMirror.prototype.leaveInsertMode,
//'Ctrl-C': false, // To enable clipboard copy
});
// ...
Summary
Tried to use the code from the customization wiki to enable \<C-c> for exiting insert mode.
Behavior
Expected
It should rebind \<C-c> to exit insert mode.
Actual
When loading notebook, in custom.js:
Step by step procedure
Paste into ~/.jupyter/custom/custom.js:
What you have done to solve the issue
Pasting the code from custom.js into the browser console after load works, as does changing
to
in vim_bindings.js, similar to what was suggested in #80. I didn't really like changing code from the repository for configuration, so I tried to change the binding again in custom.js:
It's basically the same code from the wiki, but it sticks the code into the exports.attach function from vim_bindings.js. This works for me.
Remarks
I'm still not sure if it's just an issue on my end that prevents the wiki's custom.js script from working. If other people have had the same issue and my solution works for them I'd like to add it to the customization wiki.