Hey guys I'm trying to figure out how can I take my nth arg, from my last command, without using the !:nth. In a normal bash (emacs mode) I can do that using the follow shortcuts:

<ESC>nth_arg <ESC><c-y>

how can I do the same using the bash vi mode (bash -o vi) ?

my relevant .bashrc lines

set -o vi
#BASH yank-nth-arg: <esc>narg <c-a>y
#BASH yank-last-arg: <a-.>
bind -m vi-insert '"\e.": yank-last-arg'

my current binds with yank in it:

$ bind -lp | grep 'yank'
# vi-yank-arg (not bound)
# vi-yank-to (not bound)
"\C-y": yank
"\e.": yank-last-arg
# yank-nth-arg (not bound)
# yank-pop (not bound)

currently when I try to do the:

<ESC>1 <ESC><c-y> or <ESC>1 <ALT-c-y>

I get a space/tab, or nothing happens after the (arg: 1) prompt disappears.


1 Answer 1


You can also use below bind key:

bind -m vi-insert '".": yank-last-arg'


bind -m vi-insert ".":insert-last-argument

To get the nth arguments:

bind -m vi-command '"\e-": yank-nth-arg'

Now you can use <ALT>n <ALT>- to get nth argument from previous command.

  • I think you got me wrong. In my "~/.bashrc" I already have this line (bind -m vi-insert '"\e.": yank-last-arg') and my shortcut to get the last argument works "<ALT>.". What I'm asking is to retrieve my nth argument from the last command.
    – MaikoID
    Oct 29, 2014 at 17:03
  • @MaikoID: See my updated answer.
    – cuonglm
    Oct 29, 2014 at 17:53
  • thx, with ALT doesn't work but with ESC does. So it's good for me.
    – MaikoID
    Oct 29, 2014 at 18:15
  • I don’t think anybody wants to remap . in insert mode, add \e before the dot as done by OP.
    – dessert
    Aug 22, 2018 at 14:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .