Open chiwhalee opened 6 years ago
In case if you miss, did you check https://github.com/lambdalisue/jupyter-vim-binding/wiki/Customization ?
Please write what you've tried and how did you fail with some sample code.
Thanks for response.
Yes, I‘ve tried that. Especially the snipet under title
"Move around in Insert mode with Ctrl-h/j/k/l"
......
// Use Ctrl-h/l/j/k to move around in Normal mode
// otherwise it would trigger browser shortcuts
CodeMirror.Vim.map("\
I uncommented the last two lines, but this take no effects, just as the comment itself says "The following key mappings should not be defined"
Then how about a bit modification of https://github.com/lambdalisue/jupyter-vim-binding/wiki/Customization#run-cell-scrolls-the-cell-to-top-scroll-output-into-view
// Run and select next cell
Jupyter.keyboard_manager.actions.register({
'help': 'run selected cells',
'handler': function(env, event) {
env.notebook.command_mode();
var actions = Jupyter.keyboard_manager.actions;
actions.call('jupyter-notebook:run-cell', event, env);
actions.call('jupyter-notebook:select-next-cell', event, env);
env.notebook.edit_mode();
}
}, 'run-and-next', 'vim-binding');
// Run and select previous cell
Jupyter.keyboard_manager.actions.register({
'help': 'run selected cells',
'handler': function(env, event) {
env.notebook.command_mode();
var actions = Jupyter.keyboard_manager.actions;
actions.call('jupyter-notebook:run-cell', event, env);
actions.call('jupyter-notebook:select-previous-cell', event, env);
env.notebook.edit_mode();
}
}, 'run-and-previous', 'vim-binding');
// Add two keyboard shortcuts for the new actions
require([
'nbextensions/vim_binding/vim_binding',
'base/js/namespace',
], function(vim_binding, ns) {
// Add post callback
vim_binding.on_ready_callbacks.push(function(){
var km = ns.keyboard_manager;
// Indicate the key combination to run the commans
km.edit_shortcuts.add_shortcut('ctrl-j', 'vim-binding:run-and-next', true);
km.edit_shortcuts.add_shortcut('ctrl-k', 'vim-binding:run-and-previous', true);
// Update Help
km.edit_shortcuts.events.trigger('rebuild.QuickHelp');
});
});
Note that all available jupyter mappings are written in https://github.com/lambdalisue/jupyter-vim-binding/blob/master/lib/jupyter/shortcuts.js
I want to map c-j to 5j, namely jump up 5 lines, and I tweaked the lines km.edit_shortcuts.add_shortcut('ctrl-j', 'vim-binding:run-and-next', true); to km.edit_shortcuts.add_shortcut('ctrl-j', '5j', true); or km.edit_shortcuts.add_shortcut('ctrl-j', 'vim-binding:5j', true); however with no luck.
Someone like me maybe acoustomized to use Ctrl-j/k in other ways, say, jump up/down several lines. How can I bind "running cell and jumping to cell up/down" with other keys, and release Ctrl-jk, so that I can use them as I want?