开发者

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

开发者 https://www.devze.com 2023-01-04 10:03 出处:网络
I recently made the insanely long overdue switch from tcsh to bash. The only 开发者_运维技巧thing I miss is tcsh\'s ESC+p feature:

I recently made the insanely long overdue switch from tcsh to bash. The only 开发者_运维技巧thing I miss is tcsh's ESC+p feature: 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.

Perhaps the best answer is to just get used to bash's Ctrl+r but 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+Enter to re-issue it. It's so quick that I'd usually never use up-arrow for anything more than 2 commands ago.

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.

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?


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


Add this to your ~/.inputrc file:

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

This will make PageUp act like tcsh's Esc+p and PageDown will go forward through the list.

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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号