I am using a VT100 terminal emulator on Linux. In bash, up and down arrows scroll through the last commands executed; they work as expected.
Previous (up arrow) and next (down arrow) commands are not interpreted in the Python command line interpreter. What kind of key mappings do I need to make this work?
Thank you.
Advertisement
Answer
I think I’ve found the answer, assuming you have the GNU Readline library. (This does mean I was partially wrong about the base implementation using a Unix-style interface, as it only does that when GNU Readline [or a port, I guess] isn’t available.)
http://docs.python.org/tutorial/interactive.html#history-substitution
History substitution works as follows. All non-empty input lines issued are saved in a history buffer, and when a new prompt is given you are positioned on a new line at the bottom of this buffer.
C-P
moves one line up (back) in the history buffer,C-N
moves one down. Any line in the history buffer can be edited; an asterisk appears in front of the prompt to mark a line as modified. Pressing the Return key passes the current line to the interpreter.C-R
starts an incremental reverse search;C-S
starts a forward search.