Putting
the
![](v.png)
in
IPython

Here's a link to the abstract and you can watch the video from SciPy 2014 where this talk was presented. The rest of this document are the slides I used in the talk.

Paul Ivanov

http://pirsquared.org

**@ivanov** on [Twitter](https://twitter.com/ivanov) and [GitHub](http://github.com/ivanov)

Fact:





80% of vi users simply don't know how to quit...

Public Service Announcement:

Press Escape a few times, then :q! to quit without saving. (save quit with :wq)





















Summary of the talk:

Build your own light saber!

Phrase lifted from an excellent talk by Sam Aaron

Zen and the Art of Live Programming

(I got there via this post from Tom Ballinger, thanks Tom!)





vim-ipython

Two-way integration between vim and ipython.

http://github.com/ivanov/vim-ipython

SciPy 2011

The way to get something done, sit down and talk during the sprints

with the help of Min Ragan-Kelley

Min also coined the #vimsorry hashtag for my tweets. Thanks Min!

DEMO time!

























How?

protocol

Corrolary

Vim does not need to be linked against the Python you use.

The Python your Vim is linked against just needs IPython and PyZMQ installed into it.

More details in this talk:

The IPython protocol, frontends and kernels.

Paul Ivanov and Thomas Kluyver, PyData SV 2014

( video ) ( slides )

bipython

http://bipython.org

The powers of BPython and IPython, combined!






DEMO time!






ipython vimception

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

More vi keybindings and convention in the notebook.

  • gg and G to go to top and bottom of a notebook
  • :w to save
  • dd actually cuts (so you can dd p to cut and paste cells around)

We use CodeMirror in IPython. CodeMirror supports both vim and emacs keyboard shortcuts, but you have to enable them. Here's how you do that in the notebook.

In [ ]:
%%javascript
// change the mode of all current and future CodeMirror instances
function to(mode) {
    var mode = mode || 'vim'
    // first let's apply vim mode to all current cells
    function to_mode(c) { return c.code_mirror.setOption('keyMap', mode);};
    IPython.notebook.get_cells().map(to_mode);
    // apply the mode to future cells created
    IPython.Cell.options_default.cm_config.keyMap = mode;
}

require(["components/codemirror/keymap/vim"],
     function (vim) { 
         to('vim'); 
         console.log('vim.js loaded'); 
     });

What's coming:

vim-ipython:

  • editing notebooks (unmerged branch)
  • Python3 support (unmerged branch)
  • vim help (better docs) (PR Open)

bipython:

  • kernel selection

ipython-vimception:

  • multi-cell selection and manipulation (visual mode)
  • multi-level undo
  • other ideas?

So go forth and build your own lightsaber!

Emacs users?!

Sam Aaron's Zen and the Art of Live Programming

John Kitchin's Emacs + org-mode + python in reproducible research (SciPy 2013)

John has a dovetailing follow-up talk this year: "A success story in using Python in a graduate chemical engineering course." This room 2:15 p.m.–2:45 p.m.

We use CodeMirror in IPython. CodeMirror supports both vim and emacs keyboard shortcuts, but you have to enable them. Here's how you do that in the notebook.

In [ ]:
%%javascript
// change the mode of all current and future CodeMirror instances
function to(mode) {
    var mode = mode || 'vim'
    // first let's apply vim mode to all current cells
    function to_mode(c) { return c.code_mirror.setOption('keyMap', mode);};
    IPython.notebook.get_cells().map(to_mode);
    // apply the mode to future cells created
    IPython.Cell.options_default.cm_config.keyMap = mode;
}

require(["components/codemirror/keymap/emacs"],
     function (emacs) { 
         to('emacs'); 
         console.log('emacs.js loaded'); 
     });

Then, for you, just put a call of: to('emacs') in that curly braces of that function (emacs) callback from earlier (that function's what will be called after the emacs.js file is actually loaded, because trying to call it before that won't work. So your solution should look something like this: