Bash's equivalent of Tcsh's ESC+p

6

I'm moving from Tcsh to Bash, and I would like to take the ESC+p feature with me.

If I type , say git cl, and then press ESC+p, it should complete automatically to the last command that starts with git cl (e.g. git clone something), and place the cursor at the end.

I added the following 2 lines to ~/.inputrc:

"\ep": history-search-backward
"\en": history-search-forward

which gives me exactly what I need except that the cursor is not moved to the end.

Any ideas how to fix that?

Misha Moroshko

Posted 2011-10-28T11:25:26.367

Reputation: 5 573

Answers

4

Try this:

"\ep": "\M-\C-p\C-e"
"\M-\C-p": history-search-backward

The first line defines a "macro" that inserts two keystrokes, \M-\C-p and \C-e. The first keystroke you define as history-search-backward, and the 2nd is already defined as end-of-line.

Andrew Schulman

Posted 2011-10-28T11:25:26.367

Reputation: 2 696

Adding this to my inputrc right now, something I was curious about myself! – Rob – 2011-11-01T17:31:52.470

It works, but I didn't think about what it would do to searching through multiple entries. I usually will type in ssh and go through the history search. Moving the cursor to the end of the line kind of ruins that. – Rob – 2011-11-01T17:41:43.910

Exactly - I don't care for this command combination myself, because as you say it breaks searching through multiple matching entries. But it's what Misha asked for. – Andrew Schulman – 2011-11-01T17:44:20.630

1

Doing control-r first (or once the common part of the command typed, like after git, then typing the rest and hitting End will do it in the same number of key-presses as Esc-P :)

Paul

Posted 2011-10-28T11:25:26.367

Reputation: 52 173