设置'set -o vi'时,有什么方法可以使Ctrl + L清除屏幕吗?


Answers:


61

Ctrl+ L也在vi命令模式下绑定,但在插入模式下不绑定。clear-screen在插入模式下没有默认绑定。Readline绑定应在中指定~/.inputrc,如下所示:

set editing-mode vi
$if mode=vi

set keymap vi-command
# these are for vi-command mode
Control-l: clear-screen

set keymap vi-insert
# these are for vi-insert mode
Control-l: clear-screen 
$endif

在正常模式和插入模式下,这将绑定Ctrl+ L清除屏幕。自然,如果您只想在一种模式下使用它,只需删除相关选项即可。

大量的readline命令,可用于自定义bash shell。


1
出于好奇,如果vi命令已经被映射,为什么还要打扰它呢?仅出于完整性考虑,还是有技术原因?
肯·贝罗斯

2
@KenBellows为清晰起见,根据评论(出于纯粹的审美原因,我需要在vi命令块中添加一个示例)。
jasonwryan

22

将此行放入您的bashrc

bind -m vi-insert "\C-l":clear-screen
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.