开发者

bash/readline equivalent of escape-dot in vi-mode

开发者 https://www.devze.com 2023-03-23 17:10 出处:网络
Having recently switched to vi-mode in bash, the one thing I 开发者_如何学Cmiss is esc . to get the last argument of the last command.

Having recently switched to vi-mode in bash, the one thing I 开发者_如何学Cmiss is esc . to get the last argument of the last command.

I know about ctrl _, but I always end up hitting ctrl - instead.

Is there another vi-mode equivalent for this?


I believe the closest solution to what you want is this:

In your .bashrc, right after "set -o vi"...

set -o vi
bind -m vi-command ".":insert-last-argument

This tells your bash to invoke the "insert-last-argument" action when '.' is used in vi-command mode. This of course means that you lose the normal "." functionality of VI; but if you are like me, you'll prefer this.

Addendum: You may also want Ctrl-A, Ctrl-E, Ctrl-W and Ctrl-L to work (those were the ones I was missing the most):

bind -m vi-command ".":insert-last-argument
bind -m vi-insert "\C-l.":clear-screen
bind -m vi-insert "\C-a.":beginning-of-line
bind -m vi-insert "\C-e.":end-of-line
bind -m vi-insert "\C-w.":backward-kill-word


You can also use the following to restore the emacs "escape-dot inserts last argument" behaviour in vi mode:

bindkey -v '\e.' insert-last-word


By altering or adding ~/.inputrc

To restore certain bash goodies in vi-mode, simply alter or add ~/.inputrc like this:

set completion-ignore-case on
set show-all-if-ambiguous on
set show-all-if-unmodified on

set editing-mode vi
set keymap vi-insert

$if mode=vi
"\C-a": beginning-of-line
"\C-e": end-of-line
"\C-l": clear-screen
"\C-n": next-history
"\C-p": previous-history
"\C-w": backward-kill-word

"\e.": yank-last-arg
"\e_": yank-last-arg
$endif

Here are more bindable readline bash commands.


I always used alt . to get the last argument of the last command.

Also, the !$ will give you the last argument of the last command executed. There are a bunch of cool things you can do with the exclamation point, just check out the man page for bash and search for History Expansion.


How about just using $_ bash variable?


I'm pretty sure you can still use the equivalent for vi mode, which should be "ESC + ."

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号