4

In zsh by default, CTRL+w and ALT+Backspace seem to have exactly same effect.

How can I keep CTRL+w as it is, and change ALT+Backspace so that it stops at non-alphanumeric characters.

ie, when the cursor is at the end of following command: echo /aaa/bbb/ccc, pressing CTRL+w should leave echo, while pressing ALT+Backspace should leave echo /aaa/bbb/.

6

Actually I don't see this listed in zsh bindings, but if bindkey shows it for you, then it's configurable by binding to a function that you define.

Working from my answer in

    i use this bit contributed by someone on the list (Oliver Kiddle); check
    the archives from Mon, Oct. 8 for more info on this:

    tcsh-backward-delete-word () {
      local WORDCHARS="${WORDCHARS:s#/#}"
      zle backward-delete-word
    }

    i have it bound to control-W with:
    bindkey '^W' tcsh-backward-delete-word

    but you can change that obviously.

    i think that's what you're looking for, no?

    the '$WORDCHARS' variable is how zsh determines word boundaries so you
    could add '/' to that globally, however this might affect other things
    you want to leave it for, so i prefer this function.

So: you can use $WORDCHARS as a local variable in your own function, defining words as you want, and binding it to an arbitrary key.

When you define your function, don't forget to add it as a keymap:

zle -N tcsh-backward-delete-word
  • would you mind adding a working example for alt+backspace? When I tried your example, I get: No such widget tcsh-backward-delete-word. – 400 the Cat Oct 5 '16 at 6:06
  • The example assumes you have defined a function tcsh-backward-delete-word (with $WORDCHARS set to the characters you want for "works"). – Thomas Dickey Oct 5 '16 at 7:50
  • - that's what I did. And I get the above mentioned error: no such widget .... – 400 the Cat Oct 5 '16 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.