readline + python + vi-editing-mode

Ned Deily nad at
Thu Oct 18 15:08:21 PDT 2012

In article < at>,
 laurence <from-nabble at> wrote:

> I'm trying to enable vi editing mode in readline in Python. Here's what I'm
> doing in an interactive Python session:
> >>> import readline
> >>> import rlcompleter
> >>> readline.parse_and_bind ("bind ^I rl_complete")
> >>> readline.parse_and_bind("tab: complete")
> >>> readline.parse_and_bind('set editing-mode vi')
> To test if it's working, I type a few words, and then tap ESC and 'b' a few
> times. That should take me back word-by word. On my Linux box this works as
> expected, but on my Mac with MacPorts it doesn't, and I don't understand
> why. Tapping b repeatedly moves me back one word, but then starts inserting
> b's, so it seems to be still in emacs mode.
> I thought I might have accidentally run the Apple build of Python (I know it
> has... issues with readline due to GPL), but it looks like I'm using the
> MacPorts version:
> >>> rlcompleter.__file__
> '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/rlc
> ompleter.pyc'
> >>> readline.__file__
> '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib
> -dynload/'
> Any ideas?

Did you install the py27-readline port?  If not, modern Pythons on OS X 
will link with the Apple-supplied BSD libedit which has a different 
syntax for its bind commands.  py27-readline replaces the Python 
readline with one linked with the GNU libreadline.  Some more info here:

 Ned Deily,
 nad at

More information about the macports-users mailing list