[英]To bind clear to ^l in Bash
I would like to have Ctrl-l
for clear
in my Bash.我想在我的 Bash 中
clear
Ctrl-l
。
How can you bind Ctrl-l
to clear
in Bash?如何在 Bash 中绑定
Ctrl-l
以clear
?
Put this in your ~/.inputrc
:把它放在你的
~/.inputrc
:
C-L: backward-kill-line
(assuming by "clear" you mean "clear current input line"; if you mean "clear screen" then put clear-screen
instead of backward-kill-line
). (假设“清除”的意思是“清除当前输入行”;如果您的意思是“清除屏幕”,则放置
clear-screen
而不是backward-kill-line
)。
in a particular case where the clear-screen
didn't work for me either, I found out that putting in ~/.bashrc
the line: bind -x $'"\\Cl":clear;'
在
clear-screen
对我也不起作用的特定情况下,我发现在~/.bashrc
中放入一行: bind -x $'"\\Cl":clear;'
was better than "\\Cl":'clear\\n'
in ~/.inputrc
because it cleared the screen and left the currently typed command in place;比
~/.inputrc
"\\Cl":'clear\\n'
更好,因为它清除了屏幕并将当前键入的命令留在原地; for example ( ^L
show where I hit the combo):例如(
^L
显示我击中组合的位置):
With "\\Cl": clear-screen
in ~/.inputrc
:使用
"\\Cl": clear-screen
in ~/.inputrc
:
user@darkstar:~$ date^L
user@darkstar:~$ date
user@darkstar:~$ ^L
user@darkstar:~$
With "\\Cl":'clear\\n'
in ~/.inputrc
:在
~/.inputrc
使用"\\Cl":'clear\\n'
:
user@darkstar:~$ date^L
-bash: dateclear: command not found
user@darkstar:~$ ^L
# screen effectively redrawn
With bind -x $'"\\Cl":clear;'
使用
bind -x $'"\\Cl":clear;'
in ~/.bashrc
:在
~/.bashrc
:
user@darkstar:~$ date^L
# screen redrawn and the top line is now:
user@darkstar:~$ date
And for now I have not been able to get the same result as bind -x
using only the inputrc file...而现在我还无法获得
bind -x
仅使用 inputrc 文件的bind -x
相同的结果......
I found that in some cases where clear-screen
wasn't working for me were caused by my attempts to get more colors in the CLI.我发现在某些情况下,
clear-screen
对我不起作用是因为我试图在 CLI 中获得更多颜色。 For example I had the issue with TERM=xterm-256color
(or screen-256color
, etc.) and removing the -256color
part solved the problem.例如,我遇到了
TERM=xterm-256color
(或screen-256color
等)的问题,删除-256color
部分解决了问题。
I have not yet found a way to get a 256 colors term working along CTRL + l (in xterm, urxvt, etc).我还没有找到一种方法来获得一个 256 色的术语,它可以与CTRL + l一起工作(在 xterm、urxvt 等中)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.