标签:
如果支持,在交互式命令输入中,当前行可以使用以下的快捷键进行编辑:
Ctrl+A:将光标移动到行开始位置
Ctrl+E:将光标移动到行结束位置
Ctrl+B:将光标往左移动一个位置
Ctrl+F:将光标往右移动一个位置
Backspace擦除光标左边的一个字符
Ctrl+D:擦除光标右侧一个字符
Ctrl+K:擦除光标右侧所有字符
历史命令补全工作原理如下:将所有从命令行中输入的非空行保存在历史缓存中,当你在新的一行中输入命令 时,使用Ctrl+p输入历史命令中的上一条命令,使用Ctrl+N输入历史命令中的下一条命令。
通过~/.inputrc可以自定义快捷键。格式如下所示
key-name: function-name #or "string": function-name
set option-name value
# I prefer vi-style editing: set editing-mode vi # Edit using a single line: set horizontal-scroll-mode On # Rebind some keys: Meta-h: backward-kill-word "\C-u": universal-argument "\C-x\C-r": re-read-init-file
Tab: complete
import rlcompleter, readline readline.parse_and_bind(‘tab: complete‘)
1 # Add auto-completion and a stored history file of commands to your Python 2 # interactive interpreter. Requires Python 2.0+, readline. Autocomplete is 3 # bound to the Esc key by default (you can change it - see readline docs). 4 # 5 # Store the file in ~/.pystartup, and set an environment variable to point 6 # to it: "export PYTHONSTARTUP=~/.pystartup" in bash. 7 8 import atexit 9 import os 10 import readline 11 import rlcompleter 12 13 historyPath = os.path.expanduser("~/.pyhistory") 14 15 def save_history(historyPath=historyPath): 16 import readline 17 readline.write_history_file(historyPath) 18 19 if os.path.exists(historyPath): 20 readline.read_history_file(historyPath) 21 22 atexit.register(save_history) 23 del os, atexit, readline, rlcompleter, save_history, historyPath
标签:
原文地址:http://www.cnblogs.com/fireflow/p/4865675.html