On a terminal, Alt+char is normally the same as Esc char. (It's possible to configure some terminals differently.)
In vi insert mode, Esc switches to command mode. In vi command mode, Esc does nothing. In vi command mode, . repeats the last command.
The widget insert-last-word
is bound to Alt+. and Alt+_ by default in emacs mode, but it doesn't have a default binding in vi mode. If you want to use it in vi mode, you need to give it a binding, e.g.
bindkey -M vicmd _ insert-last-word
Note that this is an insert command: it inserts the text before the cursor, which can't be done at the end of a line. This is rather inconvenient for a command that's very often used at the end of a line. You may prefer to define append-last-word
instead.
function append-last-word { ((++CURSOR)); zle insert-last-word; }
zle -N append-last-word
bindkey -M vicmd _ append-last-word
ESC
will bring the cursor back, requiring me to enter two blanks before hittingESC _
orAlt _
. Is there a better way to do this? – mcp Jan 04 '22 at 21:07