Shell – Zsh completion that is insensitive between `_` and `-`

autocompleteshellzsh

I don't like typing underscores, and would like to type a dash instead, and have zsh autocompletion treat it like it could be either a dash or an underscore.

Is this possible with built-in zsh capabilities, oh-my-zsh or something else? Would it be possible globally, and if not, would it be possible for a single autocompletion function?

Aside: I currently have a customized completion function for bashmarks that just translates underscores to dashes when providing possible completions, and would like to replace/improve it.

Best Answer

The zshcompsys man page has a similar example to get case insensitive completion

zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'

Changing it to make - and _ equivalent seems to do what you want

zstyle ':completion:*' matcher-list '' 'm:{-_}={_-}'

Or you could add it to the first example, and get case insensitive completion too

zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z-_}={A-Za-z_-}'