12

我最近从 tcsh 到 bash 进行了过期已久的转换。我唯一想念的是 tcsh 的ESC+p功能:开始输入命令,然后按ESC+ p(实际上我发现等效的 ctrl-[p 更容易输入)它会跳转到您历史中以您的内容开头的最新命令到目前为止打字。

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

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

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

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

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

4

4 回答 4

11

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

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

$ cat ~/.inputrc
"\ep": history-search-backward
"\en": history-search-forward
于 2010-06-21T18:09:28.090 回答
10

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

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

这将使PageUp行为像 tcsh 的Esc+p并且PageDown将在列表中前进。

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

于 2010-06-21T17:36:25.330 回答
3

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.

于 2010-06-21T21:29:06.497 回答
2

好吧,你可以做

!.

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

于 2010-06-21T17:18:19.540 回答