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

Re: next-word vs. next-word-segment?



Jay Levitt wrote:
> TextMate on the Mac has a handy feature: you can jump to the next word
> as always, with option-right-arrow, but you can also jump to the next
> word segment (CamelCase, under_score, hyphen-ated) with
> control-right-arrow. This solves the age old "which word boundaries do I
> care about more?" problem.
>
> Is there a way to do something like this easily in zsh?  I'm on 4.3.6
> (but could upgrade to 4.3.10 if needed).

I can't remember if you need to upgrade to get this (I think you
probably do); check the zshcontrib manual to see if it mentions the
subword-range style, if not your zsh is too old.

The easiest way to get this behaviour is to intercept the normal
backward- and forward-word commands:

  autoload -U select-word-style
  select-word-style normal
  WORDCHARS='*?.[]~=/&;!#$%^(){}<>'
  select-word-style Normal

The capital "N" is important.  You can tweak WORDCHARS if you like, I've
simply removed "-" and "_".

You can also do this entirely with styles for particular functions, so
that it doesn't affect the default behaviour, but that's a little more
involved.  The following worked for me:


# Acquire the functions provided with the shell
autoload -U forward-word-match backward-word-match
# Turn them into widgets with sensible names
zle -N forward-subword forward-word-match
zle -N backward-subword backward-word-match

# Make them have standard word behaviour, except with subwords active
zstyle ':zle:*-subword*' word-style normal-subword
# Set the characters which can be in words (exclude "-" and "_")
zstyle ':zle:*-subword*' word-chars '*?.[]~=/&;!#$%^(){}<>'

# Bind the keys.
# These are on my X server, MacOS is almost certainly different
# control forward-arrow
bindkey '\e[1;5C' forward-subword
# control back-arrow
bindkey '\e[1;5D' backward-subword


--
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


'member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom'



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