Complicated usage, but simpler setup:
You can bind a keystroke (I'll use Ctrl-Q) to the
copy-backward-word function and do this:
Alt-2 Ctrl-Q Ctrl-y Ctrl-Alt-h
copy-backward-word (copy the two preceding words)
backward-kill-word (get rid of the extra word)
To bind the keystroke at the command line:
bind '"\C-q": copy-backward-word'
or add this to your
Simpler usage, but more complicated setup:
You can make that long keystroke sequence into a macro triggered by one keystroke (I'll use Alt-q here and make use of the Ctrl-q binding from above):
At a shell prompt:
bind '"\eq": "\e2\C-q\C-y\e\C-h"'
or in your
Remember, you'll also need to bind Ctrl-q as above.
Now to copy the word before the current one all you need to press is Alt-q.