Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: history expansion



On Tue, 30 Apr 2002, Roman Neuhauser wrote:

> Is there a way ^foo^bar substitution could replace all occurrences of
> foo in the preceding event like !!:gs/foo/bar/?

Not in the way you think, no.  ^foo^bar is, very literally, shorthand for
!!:s^foo^bar -- there's no provision for inserting a `g' to the left of
the leftmost carat.

However, you can always create a special ZLE widget.  The following is
pretty much exactly what the history code does:

function insert-bangbang-gs-and-accept {
    setopt localoptions noksharrays noshwordsplit
    [[ $BUFFER[1] == $histchars[2] ]] && BUFFER='!!:gs'$BUFFER
    zle .accept-line
}
zle -N insert-bangbang-gs-and-accept



Messages sorted by: Reverse Date, Date, Thread, Author