I use alacritty and currently, I have these key binding

  # (macOS only)
  - { key: N,        mods: Command, action: SpawnNewInstance             }
  - { key: F,        mods: Command, command:
    { program: "osascript",
      args: ["/Users/sand/.dotfiles/alacritty-fullscreen.applescript"] } }
  # ...
  - { key: Delete,                  chars: "\x1b[3~"                     }

I also using tmux with

# Needed for CTRL-Left/Right to work.
setw -g xterm-keys on

# Use vi key bindings in copy mode.
setw -g mode-keys vi

# Search mode vi
set-window-option -g mode-keys vi

I would like to have vi binding for zsh, but the thing I missed the most is option+delete will delete 1 word backwards in INSERT mode like I have in zsh emacs mode. I know that I can use <C-W> to delete word but I really get used to Option-Delete. It's also consistent with what I used in the browser textbox, google doc... to delete 1 word so I'd like to keep it. How could I achieve this?

And I also notice that if I enter some text in zsh vi mode, hit ESC to go to NORMAL mode, then back to INSERT mode using i, I can not delete previously entered text using delete key anymore. I can only enter new characters, or back to NORMAL mode and cc, dd to delete text. Any idea?

1 Answer 1


To bind Alt-Backspace (Alt is Option on a Mac, isn't it?) to delete word backwards, try:

bindkey '^[^?' backward-kill-word

backward-kill-word (which is bound to Alt-Backspace in emacs mode) deletes back until the last word, and vi-backward-kill-word (which is bound to <C-w> in vi mode) deletes back until the last word, but without going past the point where insert mode was last entered. (Source: man zshzle.) This is the only difference, however they have a different value for $WORDCHARS, which is an environment variable you can set in your .zshrc to specify which characters are considered part of a word. So if you set yourself into vi mode, but then rebind <C-w> and backspace to use the regular backward-kill-word and backward-delete-char instead of the vi versions, like so in your .zshrc:

bindkey '^W' backward-kill-word
bindkey '^?' backward-delete-char

...then now you can erase things with these keybindings, even beyond the point where insert mode was last entered. The problem is that now more characters are considered part of words, such as /, so <C-w> deletes an entire file path, which is very annoying. (That's how I found this question.) That's because / is part of $WORDCHARS, so to fix it, just remove any characters from $WORDCHARS which you don't want, like this, in your .zshrc:


(This removes the /, which is written as \/ because it's escaped.) I personally also removed the - character. Maybe there are more to remove. Finally, just in case, this is what the default value of $WORDCHARS looks like on my system without removing anything:

  • @San Nguyen Any reason you haven't accepted this answer yet? Jun 28, 2020 at 20:08
  • So ^[ means Alt and ^? means backspace? Where does one learn these? What is that syntax called please? Sorry I'm still new to all this.
    – J86
    Aug 25, 2023 at 13:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .