lambdalisue / jupyter-vim-binding

Jupyter meets Vim. Vimmer will fall in love.
2.1k stars 136 forks source link

Custom VIM binding to call Jupyter action in normal mode #102

Closed DrJimFan closed 7 years ago

DrJimFan commented 7 years ago

Is there an easy way to create a custom VIM binding for Jupyter action in VIM-normal mode? I've read through the customization wiki, but it doesn't cover this use case.

For example, I want to create a new cell below by Ctrl-O in VIM-normal mode. It's very inconvenient to type shift-ESC -> Jupyter mode -> o to achieve the same thing.

Another scenario is Ctrl-2 or Cmd-2 to change the current cell to markdown in VIM-normal mode.

Thanks!

lambdalisue commented 7 years ago

Supported via https://github.com/lambdalisue/jupyter-vim-binding/commit/ccee930bb8ec10d7a778416bb3ef9d6eef6bb6b0

Add followings to your ~/.jupyter/custom/custom.js

// Configure Jupyter Keymap
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;
    // Allow Ctrl-2 to change the cell mode into Markdown in Vim normal mode
    km.edit_shortcuts.add_shortcut('ctrl-2', 'vim-binding:change-cell-to-markdown', true);
    // Update Help
    km.edit_shortcuts.events.trigger('rebuild.QuickHelp');
  });
});

Note that you can use Ctrl-o, o or Ctrl-o Ctrl-o in Vim normal mode already so I don't think remapping Ctrl-o in Vim normal mode is good idea. See the "Vim command mode help" for detail

screenshot 2017-06-24 01 43 20