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

Re: Mimicking tcsh line-editing behavior



On Thu, 2 Jul 2009 19:46:19 +0000 (GMT)
Rhyme Tan <rhymetan@xxxxxxxxxxxxxx> wrote:
> My default shell is tcsh. In tcsh I can use alt(meta)-backspace, alt-F or alt-B to delete, or move forward or backward through a path.
> 
> For example I type:
> 
> ls /An/Example/of/a/Path/Name/
> 
> To delete Path/Name/, I simply hold down the alt key and press
> backspace twice (alt-backspace x2). This will leave me with the path
> &quot;/An/Example/of/a/&quot;. I cannot do this in zsh because pressing
> alt-backspace will delete the whole path (that is,
> &quot;/An/Example/of/a/Path/Name/&quot;). Is there some magic config
> option I can pass to zsh to duplicate the behavior of alt-backspace, -F,
> or -B) in tcsh?

Sounds like the simple solution

WORDCHARS=${WORDCHARS//\/}

is OK for you.

For anyone trying to do more, look at the zshcontrib manual for
select-word-style which allows you to do all sorts of things like this
very easily, with different configurations for different bindings, and
even different places on the command line and words matching different
patterns.

The following is what I have, but the possibilities are endless.

    # This activates the system and makes whitespace-separated
    # words the default.
    autoload -U select-word-style
    select-word-style whitespace

    # This sets up a function that doesn't treat / as a word character.
    # It only binds it for backward-kill-word, but all the normal
    # word functions can be rebound similarly.
    zstyle ':zle:backward-kill-word-slash*' word-style normal
    zstyle ':zle:backward-kill-word-slash*' word-chars ${WORDCHARS//\/}
    zlewidget '^x/' backward-kill-word-slash backward-kill-word-match

    # This (completely separate from the above) extends word contexts
    # so that "whitespace" is space betwen words, anything with
    # a slash in is "filename", anything with a comma or equals is
    # "list", the end of the line is "end", anything else is "other".
    zstyle ':zle:*' word-context "[[:space:]]" whitespace "*/*" \
      filename "*[,=]*" list "" end "*" other
    # Transposing words swaps shell words if you're between words.
    zstyle ':zle:transpose-words:whitespace' word-style shell
    # Transposing words only swaps alphanumeric characters when
    # in a string with a /
    zstyle ':zle:transpose-words:filename' word-style normal
    zstyle ':zle:transpose-words:filename' word-chars ''
    # Any of the kill functions use a reduced notion of word characters
    # (i.e. stop killing on a larger set of characters) when in
    # an argument that looks like a list.
    zstyle ':zle:*kill-*:list' word-style normal
    zstyle ':zle:*kill-*:list' word-chars '-_.~'

zlewidget is just a simple shortcut:

   zlewidget() {
     zle -N $2 $3
     bindkey $1 $2
  }

Comments about the system are welcome, it's supposed to be general
enough to prevent people reinventing the wheel, but apparently wasn't...

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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