readline + python + vi-editing-mode

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


In article <1350591062071-197263.post at n4.nabble.com>,
 laurence <from-nabble at xenomachina.com> 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/readline.so'
> 
> 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:

http://stackoverflow.com/questions/7116038/python-tab-completion-mac-osx-
10-7-lion/7116997#7116997

-- 
 Ned Deily,
 nad at acm.org



More information about the macports-users mailing list