Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I set up my bash to replace ESCAPE+_ with the last word from the previous command?

share|improve this question

migrated from serverfault.com Jan 27 '13 at 16:05

This question came from our site for system and network administrators.

    
AFAICT, that's what bash does by default (enter the last word from the previous command when you press the Escape key followed by the _ one. Could you please clarify what you mean? –  Stéphane Chazelas Jan 27 '13 at 20:37

3 Answers 3

up vote 2 down vote accepted

Try with Alt-.

Then lets see whether ESC-_ works.

share|improve this answer

In the readline library that bash uses for these commands, the command for manipulating the shell history in this fashion is yank-last-arg, by default bound to Mod1. and Mod1_, where Mod1 is typically Alt or Escape:

yank-last-arg (M-., M-_)
Insert the last argument to the previous command (the last word of the previous history entry). With an argument, behave exactly like yank-nth-arg. Successive calls to yank-last-arg move back through the history list, inserting the last argument of each line in turn.1

You can use either; or you can bind it to another sequence in your .inputrc, like so:

"\ep": yank-last-arg

which would bind it to Mod1p.


1. http://linux.about.com/library/cmd/blcmdl3_readline.htm

share|improve this answer

You can also use !$ but that does not paste the actual word into the command line for editing like Esc-_ does.

http://www.gnu.org/software/bash/manual/bashref.html#History-Interaction

share|improve this answer
    
Bash provides some commands to perform the expansion of the current line. For example history expansion is done by the history-expand-line command which is mapped to M-^ in emacs mode by default. –  user1146332 Jan 27 '13 at 18:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.