ohmyzsh: Tab completion broken when file names contain underscores.

e.g.

mkdir test
touch a.z b.z c.z d.z a_.z b_.z c_.z
ls <tab>

on the first tab you see

ls .z

on the second, you see

a.z  b.z  c.z  d.z

files with underscores are not shown.

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 17 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I’m also working on having a better default that works for everybody. So far, I found this proposal from stackoverflow that enables fuzzy matching and it also works for the original files that had issues completing (https://github.com/robbyrussell/oh-my-zsh/issues/1398#issue-8184366).

For now you can use this (add it at the end of your zshrc file), until I have the proper time to test each candidate, read up on @Gravemind’s proposal and present a viable PR. Enjoy and report back any issues:

zstyle ':completion:*' matcher-list 'r:[[:ascii:]]||[[:ascii:]]=** r:|=* m:{a-z\-}={A-Z\_}'

#5435 fixes this, I guess I can merge it immediately given that you’ve been running with that since January. Thanks guys!

👍 Thanks for taking the time to look into that. This is still one of the biggest annoyances to date for me.

I took time to find (and understand) this bug, here is what I found:

The r:|[._-]=* matcher makes any completion with ., _, or - in file names useful when:

to complete veryverylongfile.c rather than veryverylongheader.h […] you can just type very.c before attempting completion. - http://zsh.sourceforge.net/Doc/Release/Completion-Widgets.html#Completion-Matching-Control

But really does not seem worth it: it makes any completion with ., _, or - in file names really annoying, and you already can type very[TAB]c.

So, here it fixes #1398, #4599, and #4063 (and keeps the other neat substring completion):

diff --git a/lib/completion.zsh b/lib/completion.zsh
index f5b2924712..85c892165d 100644
--- a/lib/completion.zsh
+++ b/lib/completion.zsh
@@ -12,14 +12,14 @@ zmodload -i zsh/complist

 ## case-insensitive (all),partial-word and then substring completion
 if [ "x$CASE_SENSITIVE" = "xtrue" ]; then
-  zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
+  zstyle ':completion:*' matcher-list 'r:|=*' 'l:|=* r:|=*'
   unset CASE_SENSITIVE
 else
   if [ "x$HYPHEN_INSENSITIVE" = "xtrue" ]; then
-    zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
+    zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*'
     unset HYPHEN_INSENSITIVE
   else
-    zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
+    zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'
   fi
 fi