Issue
For reasons outside of my control I'm stuck using python 2.6.6 and IPython 0.10.2. I also normally use the tcsh
shell, and have gotten quite used to completing a command from the history using <A-p>
(i.e. pressing the ALT
key and p
). However, this doesn't work in IPython. I know I can press <C-r>
and then start typing a command, but what inevitably is happening is that I start a command, press <A-p>
, get a colon indicating some weird state, then exit out of that state, delete my command, press <C-r>
then search for my command. It's getting rather irritating. Is there any way to make <A-p>
complete my already started command by relying on the history?
Solution
Ouch, this is an old version of IPython, Python (and pip). The bad news is I don't have much experience with such an old version of IPython, the good new is; it was way simpler at that time.
Most of the shortcut and feature are provided using readline, and the python bindings of stdlib. Meaning that most likely what you are trying to configure is readline itself and not only IPython; so you can find more information on that outside of IPython !
The secret is to grep
in the source-code for parse_and_bind
, then you'll find the following example configuration, leading me to change the ~/.ipython/ipy_user_conf.py
to be like so at around line 99 (all indented an extra 4 space to be in the main()
function):
import readline
readline.parse_and_bind('set completion-query-items 1000')
readline.parse_and_bind('set page-completions no')
rlopts = """\
tab: complete
"\C-l": possible-completions
set show-all-if-ambiguous on
"\C-o": tab-insert
"\M-i": " "
"\M-o": "\d\d\d\d"
"\M-I": "\d\d\d\d"
"\C-r": reverse-search-history
"\C-s": forward-search-history
"\C-p": history-search-backward
"\C-n": history-search-forward
"\e[A": history-search-backward
"\e[B": history-search-forward
"\C-k": kill-line
"\C-u": unix-line-discard"""
for cmd in rlopts.split('\n'):
readline.parse_and_bind(cmd)
The repetition of commands make me think that what \C
,\M
or [e
mean might be system dependant. I would bet on \C
being Control, and \M
being Meta (Alt, Opt), but at least one of these line did the trick for me (and also now tab
allows to complete). See also man readline
for the list of commands you can bind to what, and enjoy! Hoping you can upgrade to Python 3 and IPython 6 at some point.
[Edit]
See Eric Carlsen second comment under this answer for how it was resolved.
Answered By - Matt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.