irritable_phd_syndrome
irritable_phd_syndrome

Reputation: 5077

Python : vi mode when reading from stdin

When I run a program that uses somevar = sys.stdin.readline(), I can't use my vi commands (I have set -o vi in my .bashrc) when entering text into stdin. Is there a way to enable this functionality when reading from stdin in a python script? I am using python2.7.

Upvotes: 2

Views: 169

Answers (1)

Hai Vu
Hai Vu

Reputation: 40753

If you have the readline module installed, try it. Here is a code snippet I copied from this page:

import readline

readline.parse_and_bind('tab: complete')
readline.parse_and_bind('set editing-mode vi')

while True:
    line = raw_input('Prompt ("stop" to quit): ')
    if line == 'stop':
        break
    print 'ENTERED: "%s"' % line

Upvotes: 2

Related Questions