Last Updated: June 07, 2018
·
1.166K
· mayuroks

OSX ipython ctrl right / left navigation

In OS X ipython shell navigation was a pain coz I couldn't navigate/skip one word forward or backward using CTRL-RIGHT / LEFT arrows. Whenever I tried doing it I would see such characters.

In [1]: celery papaya;5D;5D;5D;5C;5C;5C

A QUICK WAY TO FIX this is by installing readline and configuring .inputrc.

1) Install readline using brew

$ brew install readline

2) TRICK LIES HERE. Find which characters are sent to ipython notebook when you press CTRL-RIGHT / LEFT.

Press CTRL-V and CTRL-RIGHT. In my case it showed

^[[1;5D

REPEAT for left arrow. Press CTRL-V and CTRL-LEFT.

^[[1;5C

3) Finally, your ~/.inputrc should look like

$ cat ~/.inputrc
# ipython settings
"\e[1;5D": backward-word
"\e[1;5C": forward-word

4) Enjoy ! CTRL-RIGHT and CTRL-LEFT works now.

Some References:
https://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC14

2 Responses
Add your response

I just tested this and Control didn't work but Alt/Option did by default. I'm on Python 2.7 with OS X 10.10.4. Might make life easier on you. Hope this helps.

over 1 year ago ·