Tab completion

sjbrown shandy.b at gmail.com
Thu Apr 2 12:53:57 EDT 2009


readline.parse_and_bind('\C-n: complete')

Makes it Ctrl-n do the completion, like vim.

On Apr 2, 7:59 am, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> Does anyone use the tab-completion recipe in the docs?
>
> http://docs.python.org/library/rlcompleter.html#module-rlcompleter
>
> suggests using this to enable tab-completion:
>
> try:
>     import readline
> except ImportError:
>     print "Module readline not available."
> else:
>     import rlcompleter
>     readline.parse_and_bind("tab: complete")
>
> which is all very nice, but it makes it rather difficult to indent code
> blocks:
>
> >>> def func(x):
>
> ...
> Display all 174 possibilities? (y or n)
>
> I like tab-completion, but I'd rather not be reduced to typing spaces for
> indents in the interpreter. What do other people do?
>
> Can I bind Ctrl-tab to the completion instead of regular tab? I tried
> readline.parse_and_bind("C-tab: complete") but it still completes on
> regular tab.
>
> The GNU readline library claims that M-tab (which I guess is Alt-tab)
> will enter a tab character. Problem is that Alt-tab is intercepted by my
> window manager for something else.
>
> Any other suggestions or hints?
>
> --
> Steven




More information about the Python-list mailing list