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

Re: ctrl w behaviour: jump in front of separating characters?



On Tue, Aug 24, 2021 at 9:04 AM chiasa.men <chiasa.men@xxxxxx> wrote:
>
> What I actually want is that it goes from
> ls -l -a --color /
> to
> ls -l -a --color
> and after that to
> ls -l -a

Have a look at the backward-kill-word-match widget from Functions/Zle
in the distribution.  The documentation for it is too long to quote
fully here.  I think you want:

autoload backward-kill-word-match
zle -N backward-kill-word backward-kill-word-match
zstyle ':zle:*' subword-range /
zstyle ':zle:*' word-chars ''
zstyle ':zle:*' word-style shell-subword

but there may be cases you haven't enumerated, e.g., for editing
substitutions you might prefer

zstyle ':zle:*' subword-range '][<>{}() /$'

> ls -l -a --color # mind the blank, which is unwanted too
> ls -l -a # that unwanted blank again

That's a bit trickier because an unquoted space is nearly always
considered to be "between" words, there's probably a way to get
backward-word-match to do it but I'll leave that to someone else to
figure out.  Writing your own widget:

backward-kill-word-space() {
  backward-kill-word-match
  while [[ $LBUFFER = *' ' ]] &&
    zle backward-delete-char
  do :; done
}
zle -N backward-kill-word backward-kill-word-space




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