diff --git a/lib/jupyter/actions.js b/lib/jupyter/actions.js index 3116cf2..25cd17a 100644 --- a/lib/jupyter/actions.js +++ b/lib/jupyter/actions.js @@ -381,6 +381,34 @@ define([ ); } }, 'extend-selection-below', 'vim-binding'); + + var cell_marker = {}; + + actions.register({ + 'handler': function(env, event) { + env.notebook.keyboard_manager.enabled = false; + document.addEventListener('keydown', function (event) { + env.notebook.keyboard_manager.enabled = true; + var key = event.key; + var idx = env.notebook.get_selected_index(); + cell_marker[key] = idx; + }, { once: true }); + } + }, 'mark-cell', 'vim-binding-normal'); + + actions.register({ + 'handler': function(env, event) { + env.notebook.keyboard_manager.enabled = false; + document.addEventListener('keydown', function (event) { + env.notebook.keyboard_manager.enabled = true; + 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); + }, { once: true }); + } + }, 'goto-mark-cell', 'vim-binding-normal'); }; exports.detach = function() { diff --git a/lib/jupyter/shortcuts.js b/lib/jupyter/shortcuts.js index 37c7cf3..7222570 100644 --- a/lib/jupyter/shortcuts.js +++ b/lib/jupyter/shortcuts.js @@ -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'