zsh-users
 help / color / mirror / code / Atom feed
* ctrl w  behaviour: jump in front of separating characters?
@ 2021-08-24 16:04 chiasa.men
  2021-08-24 22:32 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: chiasa.men @ 2021-08-24 16:04 UTC (permalink / raw)
  To: Zsh Users

[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ctrl w behaviour: jump in front of separating characters?
  2021-08-24 16:04 ctrl w behaviour: jump in front of separating characters? chiasa.men
@ 2021-08-24 22:32 ` Bart Schaefer
  2021-08-25 18:43   ` Daniel Shahaf
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2021-08-24 22:32 UTC (permalink / raw)
  To: chiasa.men; +Cc: Zsh Users

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ctrl w behaviour: jump in front of separating characters?
  2021-08-24 22:32 ` Bart Schaefer
@ 2021-08-25 18:43   ` Daniel Shahaf
  2021-08-25 19:29     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Shahaf @ 2021-08-25 18:43 UTC (permalink / raw)
  To: Zsh Users; +Cc: chiasa.men

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ctrl w behaviour: jump in front of separating characters?
  2021-08-25 18:43   ` Daniel Shahaf
@ 2021-08-25 19:29     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2021-08-25 19:29 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Zsh Users, chiasa.men

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?


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-25 19:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-24 16:04 ctrl w behaviour: jump in front of separating characters? chiasa.men
2021-08-24 22:32 ` Bart Schaefer
2021-08-25 18:43   ` Daniel Shahaf
2021-08-25 19:29     ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).