Aloxaf / fzf-tab

Replace zsh's default completion selection menu with fzf!
MIT License
3.37k stars 97 forks source link

Display a partial match and require a second press of tab to open fzf #8

Closed FunctionalHacker closed 2 weeks ago

FunctionalHacker commented 4 years ago

Okay this is a bit hard to explain, but here goes:

For example, when you have two files with a similar beginning, lets say file1.txt and file2.txt, most tab completion implementations I've seen works like this:

$ vim directory/f<TAB>
$ vim directory/file

At this point, when tab is pressed a second time, the completion plugin is invoked. I understand that this might be a personal preference, but I just thought to throw this idea out here.

rolandwalker commented 4 years ago

It should be as straightforward as something like

fzf-tab-partial-and-complete() {
    if [[ $LASTWIDGET = 'fzf-tab-partial-and-complete' ]]; then
        fzf-tab-complete
    else
        zle complete-word
    fi
}

zle -N fzf-tab-partial-and-complete
bindkey '^I' fzf-tab-partial-and-complete

but I'm not sure if it ideally should be a separate widget like the above, or a zstyle governing fzf-tab-complete.

NightMachinery commented 4 years ago

@rolandwalker That function doesn't work as intended when there is no common prefix: image

svanharmelen commented 4 years ago

I would love this as well... Is there any (custom) solution out there that will enable this behavior? Thanks!

Gooygeek commented 1 year ago

TL;DR: Use alt+enter to print the partial match prefix.


After way too long, I notice this line (and later the wiki documentation for it):

126: -ftb-zstyle -s print-query print_query || print_query=alt-enter

Basically, a combination of print-query=alt+enter and query-string=prefix means fzf will auto-populate the query with the longest partial match prefix and pressing alt+enter will autocomplete your command with the current query.

It's not perfect, it might add a space at the end or a slash if one of the matches is a folder. And obviously "1st tab auto-completes to the partial match prefix, 2nd tab opens fzf" would be much more desirable. But it does make life a bit easier without any modification to the existing code.

Relevant doco: https://github.com/Aloxaf/fzf-tab/wiki/Configuration#print-query

FunctionalHacker commented 2 weeks ago

This seems to be the way the plugin functions now, possibly after #413 was merged