[-- Attachment #1: Type: text/plain, Size: 1238 bytes --] my $WORDCHARS is set to ''. Consider the following path: ls -l -a --color /long/path/with-some-things/to/ consider.txt the following lines represent the modification by pressing ctrl + w each time: ls -l -a --color /long/path/with-some-things/to/consider. ls -l -a --color /long/path/with-some-things/to/ ls -l -a --color /long/path/with-some-things/ ls -l -a --color /long/path/with-some- ls -l -a --color /long/path/with- ls -l -a --color /long/path/ ls -l -a --color /long/ ls -l -a --color / ls -l -a -- 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 is that even possible just with setting the WORDCHARS accordingly? It seems the problem would be solved by jumping before the separator and not staying behind it That would result in the following sequence (I guess) ls -l -a --color /long/path/with-some-things/to/consider ls -l -a --color /long/path/with-some-things/to ls -l -a --color /long/path/with-some-things ls -l -a --color /long/path/with-some ls -l -a --color /long/path/with ls -l -a --color /long/path ls -l -a --color /long ls -l -a --color # mind the blank, which is unwanted too ls -l -a # that unwanted blank again [-- Attachment #2: Type: text/html, Size: 3600 bytes --]
On Tue, Aug 24, 2021 at 9:04 AM chiasa.men <chiasa.men@web.de> 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
Bart Schaefer wrote on Tue, 24 Aug 2021 22:32 +00:00: > Writing your own widget: > > backward-kill-word-space() { > backward-kill-word-match This should have read «zle backward-kill-word-match». > while [[ $LBUFFER = *' ' ]] && > zle backward-delete-char Curious: Any particular reason to prefer this over «LBUFFER=${LBUFFER% }»? > do :; done > } > zle -N backward-kill-word backward-kill-word-space > > Cheers, Daniel
On Wed, Aug 25, 2021 at 11:43 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote: > > Bart Schaefer wrote on Tue, 24 Aug 2021 22:32 +00:00: > > Writing your own widget: > > > > backward-kill-word-space() { > > backward-kill-word-match > > This should have read «zle backward-kill-word-match». Actually that isn't necessary, backward-kill-word-match can be run as a function as long as it is in the context of another widget, it doesn't have to be run as a widget on its own. > > while [[ $LBUFFER = *' ' ]] && > > zle backward-delete-char > > Curious: Any particular reason to prefer this over «LBUFFER=${LBUFFER% }»? I didn't confirm, but I believe the latter doesn't include the space in the undo list and kill ring?