vi shortcuts in ipython notebook

For recent versions of iPython, you can launch it with this:

ipython --TerminalInteractiveShell.editing_mode=vi

You can also set this permanently in your iPython configuration file (~/.ipython/profile_default/ipython_config.py by entering:

c.TerminalInteractiveShell.editing_mode = 'vi'

EDIT: This works much better than vimception: https://github.com/lambdalisue/jupyter-vim-binding


After a bit more research and more messing around, ivanov's vimception can be made to work pretty well.

https://github.com/ivanov/ipython-vimception

To fix the syntax highlighting, comment out line 346 in vimception.js. https://github.com/ivanov/ipython-vimception/issues/7

Also, using the %load_ext vimception does not allow one to turn vimception off, so instead just paste in the javascript as mentioned in the vimception readme.

Finally, vimception highlights the entire line in white making the text hard to read with a dark theme. This can be disabled leaving only a cursor by changing styleActiveLine line 209 in vimception.js to false.

209 cm.setOption('styleActiveLine', false);

really nice way to use python!


Here is a simple, up-to-date (ipython 3.2), snippet to add to you custom.js. It fixes the most important issues.

define([
  'base/js/namespace',
  'base/js/events',
  'jquery',
  'codemirror/keymap/vim',
  'codemirror/addon/dialog/dialog'
], function(IPython, events, $) {
  events.on('app_initialized.NotebookApp', function() {
    IPython.keyboard_manager.edit_shortcuts.remove_shortcut('esc');
    IPython.Cell.options_default.cm_config.vimMode = true;
    // codemirror dialog for cmdline and search
    $('head').append('<link rel="stylesheet" type="text/css" ' +
      'href="/static/components/codemirror/addon/dialog/dialog.css">')
    $('head').append('<style type="text/css">' +
      '.CodeMirror-dialog {opacity: 0.9 !important;}</style>');
    // avoid ipython command mode while in codemirror dialog
    var bind_events = IPython.Cell.prototype.bind_events;
    IPython.Cell.prototype.bind_events = function () {
      bind_events.apply(this);
      if (!this.code_mirror) return;
      var that = this;
      this.code_mirror.on('blur', function() {
        if ($('.CodeMirror-dialog').length > 0)
          that.events.trigger('edit_mode.Cell', {cell: that});
      });
    }
  });
});