This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: reverse search (ctrl-r) doest not work
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: ned.deily, sush
Priority: normal Keywords:

Created on 2019-12-08 01:04 by sush, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg357991 - (view) Author: sush (sush) Date: 2019-12-08 01:04
On my MacOS Mojave 10.14.6 (18G103), after upgrading python to python 3.8, the ctrl-r on the python interpreter does not work.

Here is the working python 3.7 version:
```
$ python3.7 --version 
Python 3.7.3
$ python3.7     
Python 3.7.3 (default, Mar 27 2019, 09:23:15) 
[Clang 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 10
(reverse-i-search)`a': a = 10
``` 
Note that I pressed 'ctrl-r' on my keyboard to bring up the 'reverse-i-search'.

On python3.8, ctrl-r has no response from the interpreter:
```
$ python3.8 --version
Python 3.8.0
$ python3.8          
Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 10
>>> 
```

Interestingly, the ~/.python_history files seems to be updated. Also, when I enter the 'UP' key, the older command comes up. Just that ctrl-r doesn't work.

Here is the output showing that python_history files is being written to:
```
$ rm  ~/.python_history  
$ python3.8               
Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 33
>>> ^D
$ cat  ~/.python_history 
_HiStOrY_V2_
a\040=\04033
```
msg357992 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-12-08 04:40
Most likely what is happening is that the two Python instances you are using are linked to different versions of the external readline library.  From the version information, it's clear that you are using the Python 3.8.0 from the python.org macOS installer.  That Python uses the macOS-supplied BSD editline (AKA libedit) for readline functionality.  The Python 3.7.3 you have is not from python.org and based on the prompt it looks like it was linked with a version of GNU readline which probably does bind ^R to the reverse search function by default.  As described in the Python Library Reference page for readline (https://docs.python.org/3/library/readline.html), both GNU readline and BSD editline can be tailored via configuration files; GNU readline uses ~/.inputrc while BSD editline uses ~/.editrc.

On macOS, the available configuration commands for editline are described in the man page for editrc:

man 5 editrc

In particular, you should be able to enable editline's reverse search functionality by adding the following line to ~/.editrc:

bind ^R em-inc-search-prev

where ^R is two characters, not the single character CTRL-R.
msg357995 - (view) Author: sush (sush) Date: 2019-12-08 08:37
That worked, thanks for the prompt help.
History
Date User Action Args
2022-04-11 14:59:24adminsetgithub: 83176
2019-12-08 08:37:02sushsetmessages: + msg357995
2019-12-08 04:40:34ned.deilysetstatus: open -> closed

nosy: + ned.deily
messages: + msg357992

resolution: third party
stage: resolved
2019-12-08 01:04:55sushcreate