Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 454
dreeves Avatar asked Jun 21 '10 17:06

dreeves


People also ask

Which bash shortcut or command is used jump to the beginning of the command-line?

Ctrl+A or Home: Go to the beginning of the line. Ctrl+E or End: Go to the end of the line.

How can you retrieve a command you recently typed in your terminal?

After you have typed what you are looking for, use the CTRL-R key combination to scroll backward through the history. Use CTRL-R repeatedly to find every reference to the string you've entered. Once you've found the command you're looking for, use [Enter] to execute it.

Which of the following command can be used to display the description of a command which is passed as an argument to this command?

echo command in linux is used to display line of text/string that are passed as an argument . This is a built in command that is mostly used in shell scripts and batch files to output status text to the screen or a file.

What is Ctrl Z in bash?

ctrl+z stops the process and returns you to the current shell. You can now type fg to continue process, or type bg to continue the process in the background.


1 Answers

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
like image 137
Foo Avatar answered Oct 11 '22 13:10

Foo