Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
FunctionalHacker opened this issue Jan 4, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@FunctionalHacker
Copy link

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.

@Aloxaf Aloxaf added the enhancement New feature or request label Jan 5, 2020
@rolandwalker
Copy link

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
Copy link
Contributor

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

@svanharmelen
Copy link

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

@Gooygeek
Copy link

Gooygeek commented Mar 4, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants