* Readline-like ^W behavior
@ 2003-07-03 12:50 Haakon Riiser
2003-07-03 13:21 ` Peter Stephenson
0 siblings, 1 reply; 4+ messages in thread
From: Haakon Riiser @ 2003-07-03 12:50 UTC (permalink / raw)
To: zsh-users
Is it possible to make ^W delete the word to the left of the cursor
with the same word-boundary rules as in readline/bash? Here's what
I'm looking for:
bash$ ls foo-bar | wc^W
=> bash$ ls foo-bar | ^W
=> bash$ ls foo-bar ^W
=> bash$ ls ^W
=> bash$
I currently have ^W bound to "backward-kill-word" in zsh 4.1.1,
and it behaves like this:
zsh% ls foo-bar | wc^W
=> zsh% ls foo-bar | ^W
=> zsh% ls ^W
=> zsh%
As you can see from the above, the problem is that the second ^W
delets both the "|" and the word before it. This is apparently how
the "werase" character works in canonical mode (Linux 2.4.x), though
I can't imagine why -- does it consider "|" a whitespace character?
I've also tried "vi-backward-kill-word", but it's too weak:
zsh% ls foo-bar | wc^W
=> zsh% ls foo-bar | ^W
=> zsh% ls foo-bar ^W
=> zsh% ls foo-^W
=> zsh% ls foo^W
=> zsh% ls ^W
=> zsh%
Have I overlooked a function that corresponds to the readline
"unix-word-rubout" function?
--
Haakon
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Readline-like ^W behavior
2003-07-03 12:50 Readline-like ^W behavior Haakon Riiser
@ 2003-07-03 13:21 ` Peter Stephenson
2003-07-03 14:40 ` Haakon Riiser
0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2003-07-03 13:21 UTC (permalink / raw)
To: zsh-users
Haakon Riiser wrote:
> Is it possible to make ^W delete the word to the left of the cursor
> with the same word-boundary rules as in readline/bash? Here's what
> I'm looking for:
>
> bash$ ls foo-bar | wc^W
> => bash$ ls foo-bar | ^W
> => bash$ ls foo-bar ^W
> => bash$ ls ^W
> => bash$
So you're assuming unix-word-rubout in bash? (The usual bash/readline
rules for words are to use alphanumerics only, but the default ^w
binding does what you show.)
As you're using zsh 4.1.1, you have an easy solution: redefine
backward-kill-word to the Swiss-army-knife function variant with
`-match' appended, and set the style to use whitespace word boundaries:
bindkey '^w' backward-kill-word # as before
autoload -U backward-kill-word-match
zle -N backward-kill-word backward-kill-word-match
zstyle ':zle:backward-kill-word' word-style whitespace
See the zshcontrib manual for more on these functions, implemented by
match-words-by-style (and not match-word-by-style, hence the following
patch). If you want all functions to use this behaviour, you can use
select-word-style (which you can bind to a keystroke for instant
control) instead of setting the style yourself.
Index: Doc/Zsh/contrib.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v
retrieving revision 1.26
diff -u -r1.26 contrib.yo
--- Doc/Zsh/contrib.yo 28 Mar 2003 11:34:07 -0000 1.26
+++ Doc/Zsh/contrib.yo 3 Jul 2003 13:16:50 -0000
@@ -381,12 +381,12 @@
tindex(up-case-word-match)
tindex(down-case-word-match)
tindex(select-word-style)
-tindex(match-word-by-style)
+tindex(match-words-by-style)
xitem(tt(forward-word-match), tt(backward-word-match))
xitem(tt(kill-word-match), tt(backward-kill-word-match))
xitem(tt(transpose-words-match), tt(capitalize-word-match))
xitem(tt(up-case-word-match), tt(down-case-word-match))
-item(tt(select-word-style), tt(match-word-by-style))(
+item(tt(select-word-style), tt(match-words-by-style))(
The eight `tt(-match)' functions are drop-in replacements for the
builtin widgets without the suffix. By default they behave in a similar
way. However, by the use of styles and the function tt(select-word-style),
@@ -484,10 +484,10 @@
the resulting expression is tt(bar)var(X)tt(foo).
The word matching and all the handling of tt(zstyle) settings is actually
-implemented by the function tt(match-word-by-style). This can be used to
+implemented by the function tt(match-words-by-style). This can be used to
create new user-defined widgets. The calling function should set the local
parameter tt(curcontext) to tt(:zle:)var(widget), create the local
-parameter tt(matched_words) and call tt(match-word-by-style) with no
+parameter tt(matched_words) and call tt(match-words-by-style) with no
arguments. On return, tt(matched_words) will be set to an array with the
elements: (1) the start of the line (2) the word before the cursor (3) any
non-word characters between that word and the cursor (4) any non-word
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Readline-like ^W behavior
2003-07-03 13:21 ` Peter Stephenson
@ 2003-07-03 14:40 ` Haakon Riiser
2003-07-03 14:48 ` Peter Stephenson
0 siblings, 1 reply; 4+ messages in thread
From: Haakon Riiser @ 2003-07-03 14:40 UTC (permalink / raw)
To: zsh-users
[Peter Stephenson]
>> Is it possible to make ^W delete the word to the left of the
>> cursor with the same word-boundary rules as in readline/bash?
>> Here's what I'm looking for:
>> [...]
>
> So you're assuming unix-word-rubout in bash? (The usual
> bash/readline rules for words are to use alphanumerics only,
> but the default ^w binding does what you show.)
I'm a little confused here now: bash(1) and readline(3) state
that ^W is by default bound to unix-word-rubout, which uses
whitespace for word boundaries:
unix-word-rubout (C-w)
Kill the word behind point, using white space as a
word boundary. The killed text is saved on the
kill-ring.
I tried making it explicity by putting
"C-w": unix-word-rubout
in ~/.inputrc and (as expected) it made no difference.
> As you're using zsh 4.1.1, you have an easy solution: redefine
> backward-kill-word to the Swiss-army-knife function variant
> with `-match' appended, and set the style to use whitespace
> word boundaries:
>
> bindkey '^w' backward-kill-word # as before
> autoload -U backward-kill-word-match
> zle -N backward-kill-word backward-kill-word-match
> zstyle ':zle:backward-kill-word' word-style whitespace
Thanks -- that's exactly what I was looking for! :-)
--
Haakon
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Readline-like ^W behavior
2003-07-03 14:40 ` Haakon Riiser
@ 2003-07-03 14:48 ` Peter Stephenson
0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2003-07-03 14:48 UTC (permalink / raw)
To: zsh-users
Haakon Riiser wrote:
> I'm a little confused here now: bash(1) and readline(3) state
> that ^W is by default bound to unix-word-rubout, which uses
> whitespace for word boundaries:
Yes, what I was saying was that `normal' bash/readline word functions, in
particular backward-kill-word (escape backspace), use alphanumeric word
characters, and trying to confirm that you were using what you are
indeed using. Everything is the way you expect.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-07-03 14:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-03 12:50 Readline-like ^W behavior Haakon Riiser
2003-07-03 13:21 ` Peter Stephenson
2003-07-03 14:40 ` Haakon Riiser
2003-07-03 14:48 ` Peter Stephenson
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).