[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: yank-last-arg with numeric argument doesn't work as intended in vi m

From: Chet Ramey
Subject: Re: yank-last-arg with numeric argument doesn't work as intended in vi mode
Date: Mon, 8 Jun 2020 18:30:15 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.9.0

On 6/8/20 12:46 AM, Leo Alekseyev wrote:
> With GNU readline 7.0 / bash 4.4.20(1) it appears to be impossible to
> insert nth argument of a previous command in vi mode.
> According to the manual, setting a numeric argument (e.g. Alt-1) and
> repeatedly invoking Alt-. should keep inserting nth argument from
> preceding commands. For example, issuing
> echo arg1 arg2
> echo argA argB
> and pressing Alt-1 Alt-. Alt-. inserts arg1 (first inserting argA,
> then replacing with arg1).
> However, the same sequence of operations fails in vi mode even when
> the keys are bound appropriately. In particular, pressing Alt-1 Alt-.
> Alt-. inserts argA arg2.
> Subsequent invocation of Alt-. replace arg2 with the 2nd argument of
> the preceding command, i.e. readline is now behaving as if the numeric
> argument were 2.

As you've discovered, yank-nth-arg doesn't really work smoothly with the
(moded) vi style of interaction. The reason that the repeated M-. doesn't
work as you'd expect is that vi mode saves the previous command differently
than emacs mode does, especially when there's a digit argument. That's a
relatively easy fix.

The next problem is the one I referred to in my previous message -- the
assumption that you're performing the `_' command, and consequent entering
insert mode and inserting a space. I have an imperfect solution to that.

> set keymap vi-insert
> "\e.":yank-last-arg

Even with those first two changes, which will be in the next bash devel
branch push, you'll have to be very careful with this. This key binding
introduces ambiguity: either you want to run the function bound to ESC,
which puts you into vi command mode, or you want to run yank-last-arg or
any other function with an ESC meta prefix. Readline has to read an
additional character to disambiguate, and it needs to read it with a half
second or so to be part of the key sequence (this is the standard readline
way to tell the difference between ambiguous prefixes). If you take longer
than a half second, you might find yourself running the `.' (redo) command.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]