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

Re: Readline-like ^W behavior



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@xxxxxxx>                  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.
**********************************************************************



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