junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
61.81k stars 2.35k forks source link

fzf-completion doesn't work on fresh archlinux install #3886

Closed pjhfggij closed 1 week ago

pjhfggij commented 1 week ago

Checklist

Output of fzf --version

0.53.0 (c4a9ccd6)

OS

Shell

Problem / Steps to reproduce

invoking fzf-completion yields zsh's vanilla menu instead of fzf fuzzy search menu. fzf-history-widget and fzf-file-widget work fine.

for example, cd <TAB> doesn't invoke fzf, but ctrl r and ctrl t do. .zshrc:

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

# Enable colors and change prompt:
autoload -U colors && colors

PROMPT='%~ >'
RPROMPT='%*'

# History in cache directory:
HISTSIZE=99999999
SAVEHIST=$HISTSIZE
HISTFILE=/home/user/.zsh_history

setopt auto_pushd
autoload -Uz compinit
zstyle ':completion:*' menu select
# Auto complete with case insenstivity
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'

zmodload zsh/complist
compinit
_comp_options+=(globdots)       # Include hidden files.

# Edit line in buffer ctrl-v
autoload -z edit-command-line
zle -N edit-command-line
bindkey '^v' edit-command-line

# remove duplicates in zsh_history
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_FIND_NO_DUPS
setopt HIST_SAVE_NO_DUPS

# Use vim keys in tab complete menu:
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'left' vi-backward-char
bindkey -M menuselect 'down' vi-down-line-or-history
bindkey -M menuselect 'up' vi-up-line-or-history
bindkey -M menuselect 'right' vi-forward-char

source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh 2>/dev/null
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh 2>/dev/null
source /usr/share/fzf/completion.zsh
source /usr/share/fzf/key-bindings.zsh
LangLangBart commented 1 week ago

for example, cd <TAB> doesn't invoke fzf

Try

cd ** <TAB>

or modify FZF_COMPLETION_TRIGGER[^1]

export FZF_COMPLETION_TRIGGER="" 
cd <TAB>

https://github.com/junegunn/fzf/blob/c4a9ccd6afc3698a57a6b938ebba6d85238033e2/shell/completion.zsh#L322-L326

[^1]: junegunn/fzf - README -Settings

pjhfggij commented 1 week ago

Thank you @LangLangBart that works. I came across this video in the meantime that mentions FZF_COMPLETION_TRIGGER as well, but I would struggle to find out whether setting it to an empty string is a supported use case. I couldn't find it set explicitly in my current zsh framework (z4h), so thank you.

Can I ask you by the way if you know how to set it to also fuzzy search completion of command line arguments? It doesn't seem to work right now when I try to get information on ls flags for example: ls -<TAB>

but it also didn't work when I tried: ls -**<TAB> so is it not supported out of the box by fzf's completion.zsh script?

pjhfggij commented 1 week ago

also is there a list of completions that fzf-completion supports? kill is supported for example (kill <TAB>), but variables don't seem to work (echo $FZF_<TAB> )

LangLangBart commented 1 week ago

zsh framework (z4h),

I use zsh4humans as well, what is the output of the following command ?

bindkey | grep -F '^I'

try

z4h bindkey z4h-fzf-complete Tab 
pjhfggij commented 1 week ago

sorry, I've used z4h on the previous machine, but I'm trying to write .zshrc from scratch now (hence confusion)

on z4h Tab triggers fzf completion out of the box, but when sourcing fzf zsh scripts without any framework, while export FZF_COMPLETION_TRIGGER="" does work for path completions (e.g. cd <TAB>) it still doesn't seem to complete in some contexts that worked in z4h (e.g. echo $FZF_<TAB> or ls -<TAB> mentioned above)

LangLangBart commented 1 week ago

The completion widget from zsh4humans goes much further with its functionality, allowing for the things you desire, like completion of env variables and CLI arguments.


The fzf completion widget is kept minimal for a reason.

Related comment by the maintainer:

There is some customization one can easily do for additional commands, for example doge[^1].

But completion of environment variables or CLI arguments seems to require more changes to the actual *zsh file. Usually, one has to write it themselves or use popular plugins.

[^1]: junegunn/fzf - README - Custom fuzzy completion

pjhfggij commented 1 week ago

Perfect, thank you. That explains a lot. The lines between the z4h framework and fzf weren't clear to me until now.

I will see if it will be worth installing something like fzf-tab to compensate for missing completions.

I've also noticed that export FZF_COMPLETION_TRIGGER="" now breaks some zsh completions - instead of listing the usual completions on ls -<TAB> for example fzf kicks in showing file names (instead of flags and their explanations).

One might argue though that ls --help | fzf would yield the same or even better result. So I might just stay with vanilla fzf's completion.zsh in the end

pjhfggij commented 1 week ago

I've decided to give fzf-tab a try - the author seems to have thought the problem through well and the first attempts at running it showed a lot of desirable properties (straightforward frontend to the zsh's default compsys; simple zsh codebase). Maybe it will turn out not to be as "robust" as completion integration in zsh4humans, but fingers crossed it will work for my use cases.