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

feat: use m and ~ like classic vim #153

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions lib/jupyter/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,44 @@ define([
);
}
}, 'extend-selection-below', 'vim-binding');

var cell_marker = {};

actions.register({
'handler': function(env, event) {
env.notebook.keyboard_manager.enabled = false
var oldCb = document.onkeydown;
var clear = () => {
document.onkeydown = oldCb;
env.notebook.keyboard_manager.enabled = true
};
document.onkeydown = function (event) {
clear();
var key = event.key;
var idx = env.notebook.get_selected_index();
cell_marker[key] = idx;
};
lambdalisue marked this conversation as resolved.
Show resolved Hide resolved
}
}, 'mark-cell', 'vim-binding-normal');

actions.register({
'handler': function(env, event) {
env.notebook.keyboard_manager.enabled = false
var oldCb = document.onkeydown;
var clear = () => {
document.onkeydown = oldCb;
env.notebook.keyboard_manager.enabled = true
};
document.onkeydown = function (event) {
clear();
var key = event.key, idx;
if ((idx = cell_marker[key]) == null) return;
env.notebook.select(idx);
env.notebook.get_cell(idx).focus_cell();
env.notebook.scroll_cell_percent(idx, 0, 0);
};
}
}, 'goto-mark-cell', 'vim-binding-normal');
};

exports.detach = function() {
Expand Down
2 changes: 2 additions & 0 deletions lib/jupyter/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ define([
'shift-l': 'jupyter-notebook:toggle-cell-line-numbers',
'shift-v': 'jupyter-notebook:toggle-cell-output-collapsed',
'shift-s': 'jupyter-notebook:toggle-cell-output-scrolled',
'm': 'vim-binding-normal:mark-cell',
'~': 'vim-binding-normal:goto-mark-cell',
// Defined in searchandreplace.js
// https://github.com/jupyter/notebook/blob/4.x/notebook/static/notebook/js/searchandreplace.js#L375
'/': 'jupyter-notebook:find-and-replace'
Expand Down