[IPython-user] How to get def, class or other multiline from history to current input?
fperez at colorado.edu
Thu May 22 12:55:50 CDT 2003
Jeff Kowalczyk wrote:
> I'm in the midst of a cold-turkey switch to linux, and one
> of the creature comforts I gave up was PythonWin's treatment
> of multiline python commands as single command history entries.
> When working on a new function I typically iteratively debug in
> the interpreter, for which you really need a keystroke to bring
> back the entire definition into a form which you can edit,
> including entire line additions and removals and resubmit.
> Is there any way to do this?
> Is ipython's line-based editing unsuitable for this, and such
> things only happen in the connected snippet editors (vim, etc.)
ipython's line editing is readline-based, hence it works only for single-line
editing. Writing a multi-line terminal editing system requires using curses,
which is a large, complex and not very portable system. I simply haven't gone
that route because it's far too big of a headache.
But there are a few alternatives and tools in ipython to at least help with
- the @edit command allows you to open an editor on the spot, edit something,
and be back in python. This is in practice, fairly close to multi-line
editing. Note that you can type @edit, define a function (say 'f'), and later
say '@edit f', and ipython will open again the editor with the temp file where
f was defined. Just type 'edit ?' for more details.
- @hist -n will give you a command-line history without line numbers. You can
then paste previous input into an editor window if you decide you need to work
in a full editing environment with code.
- (X)emacs support: as of 0.4.0, this is fairly complete, and gives you
within emacs a very powerful IDE-like environment. There is a section in the
manual detailing how to configure it, here's the online link to it:
I know none of these are _true_ multiline editing inside ipython itself, but
in practice I find that it's not such a hindrance. I hope this helps.
More information about the IPython-user