The purpose of readline is to improve the interactive experience with the python interpreter by improving the line editing facilities. The most important being tab completion and copy and paste.

Configuration file

The configuration file is read from the users home directory and is named pyreadlineconfig.ini. The files syntax is not the same as for GNU readline but a python syntax is used instead. The available commands are:

is used to bind the keys that are used to exit the interpreter. (Ctrl-d, ctrl-z)
is used to bind keys to editor functions
is used to unbind keys can be useful to unbind default bindings the user does not like
is used to set bell style. (none|visible|audible)
is used to enable the showing of a list of all alternative for tab completion (on|off)
show directories (on|off)
Which delimeters should be used to separate words for tab completion
Turn on debug output (on|off). Not implemented yet.
Disable pyreadline completely (True|False).
Allows use of ctrl-c as copy key, still propagate keyboardinterrupt when not waiting for input.
Set the ctrl-c double tap time interval to be used before issuing a KeyboadInterupt. Used to be able to have ctrl-c bound to copy.
Set name of history file. Default is %USERPROFILE%/.pythonhistory
Set max length of history file default 200

Here is the example config file shipped with pyreadline:

#Bind keys for exit (keys only work on empty lines
#disable_readline(True)		#Disable pyreadline completely.
from __future__ import print_function, unicode_literals, absolute_import
debug_output("off")             #"on" saves log info to./pyreadline_debug_log.txt
                                #"on_nologfile" only enables print warning messages

#Commands for moving	
bind_key("Home",                "beginning_of_line")
bind_key("End",                 "end_of_line")
bind_key("Left",                "backward_char")
bind_key("Control-b",           "backward_char")
bind_key("Right",               "forward_char")
bind_key("Control-f",           "forward_char")
bind_key("Alt-f",               "forward_word")
bind_key("Alt-b",               "backward_word")
bind_key("Clear",               "clear_screen")
bind_key("Control-l",           "clear_screen")
bind_key("Control-a",           "beginning_of_line")
bind_key("Control-e",           "end_of_line")
#bind_key("Control-l",          "redraw_current_line")

#Commands for Manipulating the History
bind_key("Return",              "accept_line")
bind_key("Control-p",           "previous_history")
bind_key("Control-n",           "next_history")
bind_key("Up",                  "history_search_backward")
bind_key("Down",                "history_search_forward")
bind_key("Alt-<",               "beginning_of_history")
bind_key("Alt->",               "end_of_history")
bind_key("Control-r",           "reverse_search_history")
bind_key("Control-s",           "forward_search_history")
bind_key("Alt-p",               "non_incremental_reverse_search_history")
bind_key("Alt-n",               "non_incremental_forward_search_history")

bind_key("Control-z",           "undo")
bind_key("Control-_",           "undo")

#Commands for Changing Text
bind_key("Delete",              "delete_char")
bind_key("Control-d",           "delete_char")
bind_key("BackSpace",           "backward_delete_char")
#bind_key("Control-Shift-v",    "quoted_insert")
bind_key("Control-space",       "self_insert")
bind_key("Control-BackSpace",   "backward_delete_word")

#Killing and Yanking
bind_key("Control-k",           "kill_line")
bind_key("Control-shift-k",     "kill_whole_line")
bind_key("Escape",              "kill_whole_line")
bind_key("Meta-d",              "kill_word")
bind_key("Control-w",           "unix_word_rubout")
#bind_key("Control-Delete",     "forward_kill_word")

#Copy paste
bind_key("Shift-Right",         "forward_char_extend_selection")
bind_key("Shift-Left",          "backward_char_extend_selection")
bind_key("Shift-Control-Right", "forward_word_extend_selection")
bind_key("Shift-Control-Left",  "backward_word_extend_selection")
bind_key("Control-m",           "set_mark")

bind_key("Control-Shift-x",     "copy_selection_to_clipboard")
#bind_key("Control-c",           "copy_selection_to_clipboard")  #Needs allow_ctrl_c(True) below to be uncommented
bind_key("Control-q",           "copy_region_to_clipboard")
bind_key('Control-Shift-v',     "paste_mulitline_code")
bind_key("Control-x",           "cut_selection_to_clipboard")

bind_key("Control-v",           "paste")
bind_key("Control-y",           "yank")
bind_key("Alt-v",               "ipython_paste")

#Unbinding keys:

bell_style("none") #modes: none, audible, visible(not implemented)
completer_delims(" \t\n\"\\'`@$><=;|&{(?")
#allow_ctrl_c(True)  #(Allows use of ctrl-c as copy key, still propagate keyboardinterrupt when not waiting for input)

history_length(200) #value of -1 means no limit

#set_mode("vi")  #will cause following bind_keys to bind to vi mode as well as activate vi mode

pyreadline with python interpreter

In your startup file (pointed to by environment variable PYTHONSTARTUP) add:

# -*- coding: UTF-8 -*-
# Example snippet to use in a PYTHONSTARTUP file
from __future__ import print_function, unicode_literals, absolute_import
    import pyreadline.rlmain
    import readline, atexit
    import pyreadline.unicode_helper
    #Normally the codepage for pyreadline is set to be sys.stdout.encoding
    #if you need to change this uncomment the following line
except ImportError:
    print("Module readline not available.")
    #import tab completion functionality
    import rlcompleter

    #Override completer from rlcompleter to disable automatic ( on callable
    completer_obj = rlcompleter.Completer()
    def nop(val, word):
        return word
    completer_obj._callable_postfix = nop

    #activate tab completion
    readline.parse_and_bind("tab: complete")
    del readline, rlcompleter, atexit

This file is included in the doc directory of the distribution.

pyreadline with IronPython


Pyreadline can be used together with IronPython. Unfortunately the binary installs of IronPython can not run pyreadline directly. You need to patch the source code to make PythonCommandLine a public class that we can override.

  • In PythonCommandLine.cs you need to change class PythonCommandLine to public class PythonCommandLine and recompile.
  • Copy from a standard python install to your ironpython path (this file is not included with fepy).

pyreadline with IPython

In IPython pyreadline is automatically used if available.


Pyreadline can do copy/paste using the clipboard. Selections can be done using shift and arrowkeys as in most windows programs.

There are three different paste functions that can be bound.

Paste windows clipboard. Assume single line strip other lines and end of line markers and trailing spaces
Paste windows clipboard as multiline code. Removes any empty lines in the code
Paste windows clipboard. If enable_ipython_paste_list_of_lists is True then try to convert tabseparated data to repr of list of lists or repr of array. If enable_ipython_paste_for_paths==True then change \\ to / and spaces to \space.

International characters

The pyreadline package now supports international characters. However using international characters in the interactive prompt can be annoying on windows since the default codepage for the terminal is an ascii codepage (850 on swedish systems) but the filesystem often uses some other codepage (1252 on swedish systems). This means the filenames containing internationl characters entered on interactive prompt will not work. The workaround here is to change the codepage of your terminal to a more suitable one using the chcp command. For swedish systems chcp 1252 does the trick but you also have to change the terminal font to a font compatible with the wanted code page in the case of a swedish system that would be e.g. lucida console, or consolas using the properties dialog for the console.

Table Of Contents

Previous topic


Next topic

Bindable commands

This Page