Bash 相当于 Tcsh 的 ESC-p 跳转到命令,从你目前输入的内容开始

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3086781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 22:14:21  来源:igfitidea点击:

Bash's equivalent of Tcsh's ESC-p to jump to command starting with what you typed so far

bashshellkeyboard-shortcutstcsh

提问by dreeves

I recently made the insanely long overdue switch from tcsh to bash. The only thing I miss is tcsh's ESC+pfeature: Start typing a command and then hit ESC+p(I actually found the equivalent ctrl-[p easier to type) and it jumps to the most recent command in your history that starts with what you've typed so far.

我最近疯狂地从 tcsh 切换到 bash。我唯一想念的是 tcsh 的ESC+p功能:开始输入命令然后点击ESC+ p(我实际上发现等效的 ctrl-[p 更容易输入)它会跳转到历史记录中的最新命令打字到此为止。

Perhaps the best answer is to just get used to bash's Ctrl+rbut so far I don't like it as much. I often start typing a command and then it occurs to me that I've issued it before. With tcsh's feature I could then do ESC+p+Enterto re-issue it. It's so quick that I'd usually never use up-arrow for anything more than 2 commands ago.

也许最好的答案是习惯 bash 的Ctrl+r但到目前为止我不太喜欢它。我经常开始输入一个命令,然后我突然想到我之前已经发出过它。随着tcsh中的功能,我可以再做ESC+ p+Enter给它重新发出。它是如此之快,以至于我通常不会对超过 2 个命令的任何东西使用向上箭头。

An example of where I found it especially nice: Long commands often start with a dot, because they're of the form

我发现它特别好的一个例子:长命令通常以点开头,因为它们的形式

./myprogram.pl -lots -of -args -and -switches

In tcsh I would issue a command like that, then maybe ls, less, tail, whatever, and then to reissue the long command, 4 keys: dot, escape, p, enter.

在 tcsh 中,我会发出这样的命令,然后可能是 ls、less、tail 等等,然后重新发出长命令,4 个键:dot、escape、p、enter。

How can I do that in Bash? Or, to make it concrete, what's the fewest number of keystrokes in bash to say "repeat the last command that started with a dot"? Can it match or beat tcsh's 4?

我怎么能在 Bash 中做到这一点?或者,更具体地说,bash 中最少的击键次数是多少次说“重复以点开头的最后一个命令”?它可以匹配或击败 tcsh 的 4 吗?

采纳答案by Paused until further notice.

Add this to your ~/.inputrcfile:

将此添加到您的~/.inputrc文件中:

"\e[5~": history-search-backward
"\e[6~": history-search-forward

This will make PageUpact like tcsh's Esc+pand PageDownwill go forward through the list.

这将使PageUp例如tcsh的行为Esc+pPageDown将勇往直前通过列表。

You can bind \epinstead. If you use PageUp/ PageDown, you may need to see what character sequence your keyboard/terminal produces. Just press Ctrl+Vthen PageUpand you'll see ^[[5~if it's the same as \e[5~.

您可以\ep改为绑定。如果您使用PageUp/ PageDown,您可能需要查看您的键盘/终端产生的字符序列。只需按Ctrl+V然后PageUp你就会看到^[[5~它是否与\e[5~.

回答by Foo

I was in the same boat as you, needing to switch to bash from tcsh.

我和你在同一条船上,需要从 tcsh 切换到 bash。

I just created a new ~/.inputrc file as follows and everything works great!

我刚刚创建了一个新的 ~/.inputrc 文件,如下所示,一切正常!

$ cat ~/.inputrc
"\ep": history-search-backward
"\en": history-search-forward

回答by Paused until further notice.

Personally I prefer ctrl-r - it's interactive search through history - check it, perhaps you'll like it. Subsequent ctrl-r presses jump to next match.

我个人更喜欢 ctrl-r - 它是通过历史进行交互式搜索 - 检查它,也许你会喜欢它。随后的 ctrl-r 按下跳转到下一场比赛。

回答by ire_and_curses

Well, you can do

嗯,你可以

!.

Which is three characters (including the Enter). Of course, in the general case, you can replace the dot with the unique identifying prefix of your choice.

其中三个字符(包括 Enter)。当然,在一般情况下,您可以将点替换为您选择的唯一标识前缀。