简体   繁体   English

Python:从标准输入读取时的vi模式

[英]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.当我运行使用somevar = sys.stdin.readline()的程序时,在将文本输入到 stdin 时无法使用 vi 命令(我在 .bashrc 中set -o vi )。 Is there a way to enable this functionality when reading from stdin in a python script?从 python 脚本中的 stdin 读取时,有没有办法启用此功能? I am using python2.7.我正在使用 python2.7。

If you have the readline module installed, try it.如果您安装了readline模块,请尝试一下。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM