Using bash in the default (emacs) mode I get the following behavior when I hit Esc, ..
$ echo hello
hello
$ hello # I hit `<ESC>.` to insert this
Note there is no space before the word hello
that is inserted when I hit Esc, ..
If I switch to vi mode and configure .
I do get a leading space:
$ set -o vi
$ bind -m vi-command ".":yank-last-arg
$ echo hello
hello
$ hello # I hit `<ESC>.` to insert this. Note the leading space.
Is there any way to configure bash/readline to avoid this leading space?
Best Answer
That really looks like a bug, but actually Bash is just trying to follow the POSIX specified behavior of
_
,As a workaround, add this to your
~/.inputrc
. You can change the\M-h
to some other unbound key if you want.Now, open a new terminal. Upon striking . in normal mode,
!$
is insterted in the command-line.\e
(means Esc) goes back to normal mode.\M-h
triggershistory-expand-line
action, which expands$!
to the value of the last argument.A
moves to the end-of-the line and enters insert mode.