Get rid of that _gd function and just add the following to your .zshrc file:
autoload -Uz compinit compinit zstyle ':completion:*' matcher-list 'r:|?=**' This tells the completion code to allow any number of additional between and around what you’ve types. With this, Zsh can now fuzzy complete anything.
In more detail:
?=r:X|Y=Zlooks for all non-overlapping substrings that match patternXYand makes it so the part matched byXalso matches any one characteranything matched by patternZwhen checking for matching completions.r:|?matches any substring that endsone character.- If (
rX) in or?Yequals (any one character)*, it matches any number of consecutive characters. r:|?=*says, in your input, from left to right, find a substring that ends in If?Z(any one character), insert aequals*(wildcard, whichit matches any number of consecutive characters) into the position indicated except anything matched by the|Yand try to find completion matches with that.- If that fails, find the next such input substring
Zequals**, until you either find one or more completionit matches or you run outany number of substringsconsecutive characters. - In
r:|?=**says, in your input, find every substring that ends in?(any one character), insert a wildcard (*X) into every position indicated by equals the|and try to find completion matches with thatempty string. - Finally, byBy default, Zsh already adds a wildcard to the end of your input, thus completing the circle for full fuzzy matching.
You can find the documentation over here: http://zsh.sourceforge.net/Doc/Release/Completion-Widgets.html#Completion-Matching-Control