Home » Questions » Computers [ Ask a new question ]

Last parameter of last command in bash in vi-mode

Last parameter of last command in bash in vi-mode

I have been convinced (over at Stack Overflow) to use my beloved bash in vi mode. So far I got used to it quite well and I like it.

Asked by: Guest | Views: 15
Total answers/comments: 3
Guest [Entry]

"There's no default. The binding for 'yank-last-arg' (as listed by 'bind -p') disappears when you switch to vi mode.

bind '""\e.""':yank-last-arg

will give you that same binding back (or pick something else)"
Guest [Entry]

Not exactly the same, but in either mode you can type !$, and it will be replaced by the last word of the previous command. Find more such things in the manual.
Guest [Entry]

"You can use $_ to refer to the last argument of the previous command.

The disadvantages are:

You can't verify before pressing Enter that the thing inserted is the thing you intended to insert.
If you use PROMPT_COMMAND or a DEBUG trap (I'm not sure which, exactly, causes the problem; I have both in my .bashrc) to do fancy stuff like put the running command into the xterm title, it will clobber $_."