Configure Ctrl+w as Delete Word in zsh – Keyboard Shortcuts

keyboard shortcutszlezsh

I want to delete a word by Ctrl+W in zsh like.

vim /foo/bar^W
vim /foo/

And found a solution for bash, but bind is not in zsh function.

Is it possible to configure ctrl-w (delete word)?

How can I configure Ctrl+W as a delete-word?

Best Answer

Here's a snippet from .zshrc i've been using:

my-backward-delete-word() {
    local WORDCHARS=${WORDCHARS/\//}
    zle backward-delete-word
}
zle -N my-backward-delete-word
bindkey '^W' my-backward-delete-word

I recall this was the original source: http://www.zsh.org/mla/users/2001/msg00870.html

Related Question