Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

vi

readline

Having recently switched to vi-mode in bash, the one thing I miss 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?

like image 479
rouge8 Avatar asked Jul 27 '11 03:07

rouge8


3 Answers

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
like image 66
ttsiodras Avatar answered Oct 27 '22 05:10

ttsiodras


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
like image 38
psynaptic Avatar answered Oct 27 '22 04:10

psynaptic


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.

like image 43
Serge Stroobandt Avatar answered Oct 27 '22 06:10

Serge Stroobandt