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

CTRL-R / CTRL-T stopped working #4211

Open
5 of 10 tasks
sum-elier opened this issue Jan 29, 2025 · 13 comments
Open
5 of 10 tasks

CTRL-R / CTRL-T stopped working #4211

sum-elier opened this issue Jan 29, 2025 · 13 comments

Comments

@sum-elier
Copy link

Checklist

  • I have read through the manual page (man fzf)
  • I have searched through the existing issues
  • For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.58.0 (65db735)

OS

  • Linux
  • macOS
  • Windows
  • Etc.

Shell

  • bash
  • zsh
  • fish

Problem / Steps to reproduce

  1. Press ctrl+r or ctrl+t to trigger either of the actions associated with the keybindings.
  2. Nothing happens.
  3. Press repeatedly, occasionally you'll see $FZF_DEFAULT_OPTS: height required: HEIGHT

I am using ZInit to install fzf:

zinit wait"0b" lucid light-mode for \
  id-as'fzf' \
    as"program" \
    from"gh-r" \
    nocompile \
    @junegunn/fzf

zinit wait"0c" as"completion" light-mode lucid for \
    id-as'zsh-completions' @zsh-users/zsh-completions \
    id-as'fzf-completion' mv'fzf-completion -> _fzf' https://github.com/junegunn/fzf/blob/master/shell/completion.zsh

zinit wait"0d" lucid light-mode for \
    id-as"fzf-keybindings" https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh \
    id-as'fzf-tab' @Aloxaf/fzf-tab

I tried reorganizing the initialization order with wait"0<something>" but that did nothing.
I haven't modified anything about fzf, how it is installed, or how it is initialized. I stopped working after updating the zinit plugins though.

@junegunn
Copy link
Owner

So it looks like you're loading the shell integration files from the master branch, but they're not guaranteed to be compatible with the latest binary released.

For this very reason, it's been a while since fzf included the scripts in the binary itself.

source <(fzf --zsh)

The error you're experiencing will be resolved once fzf releases a new version, and you upgrade the binary. But it can't break again any time.

So you have 3 options,

  1. Use fzf --zsh as shown above (recommended)
  2. Only use scripts from the matching tag. e.g. https://github.com/junegunn/fzf/blob/v0.58.0/shell/completion.zsh
  3. If you really have to use the scripts from the master branch, build fzf from the same source so that they're compatible

@sum-elier
Copy link
Author

sum-elier commented Jan 30, 2025

@junegunn thank you for responding.

I would like to use option 1 as you recommended but I am not very skilled with shell things, so I am unsure if what I need to do is the following:

zinit wait"0b" lucid light-mode for \
  id-as'fzf' \
    as"program" \
    from"gh-r" \
    nocompile \
    @junegunn/fzf

zinit wait"0c" as"completion" light-mode lucid for \
-     id-as'zsh-completions' @zsh-users/zsh-completions \
+     id-as'zsh-completions' @zsh-users/zsh-completions
-     id-as'fzf-completion' mv'fzf-completion -> _fzf' https://github.com/junegunn/fzf/blob/master/shell/completion.zsh

zinit wait"0d" lucid light-mode for \
-     id-as"fzf-keybindings" https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh \
    id-as'fzf-tab' @Aloxaf/fzf-tab

+ source <(fzf --zsh)

Is this correct?

By the way, I've had this configuration since before #3675, which might explain why I had it like that. Would it be possible to detect old init configurations of fzf?

@junegunn
Copy link
Owner

Is this correct?

I'm a bash user and have no experience with zinit, so I can't tell if that's the best way to do it, but if it works, I guess so.

Would it be possible to detect old init configurations of fzf?

The scripts can check the output of fzf --version and see if they're compatible with the binary, but that will increase the start up time by a few milliseconds even on working systems, so it's a trade-off.

@sum-elier
Copy link
Author

I'm a bash user and have no experience with zinit, so I can't tell if that's the best way to do it, but if it works, I guess so.

To better understand what I am doing, the output from fzf --zsh is the same as completion.zsh and key-bindings.zsh?

@junegunn junegunn added the shell label Jan 30, 2025
@junegunn
Copy link
Owner

junegunn commented Jan 30, 2025

Yes, it prints the contents of both files at the time of the build. Each section starts and ends with a special comment, so you can use something like sed to opt-out a file if you don't want it. See #3675 (comment)

so that users can specify

  • sed -n '/^### completion/,/^### end/p'
  • or sed -n '/^### key-bindings/,/^### end/p'
  • or sed -n '/^### key-bindings/,/^### end/p;/^### completion/,/^### end/p'.

Originally posted by @akinomyoga in #3675 (comment)

@sum-elier
Copy link
Author

sum-elier commented Jan 30, 2025

Thank you for helping me out with this. It does work, I had to register it as a callback to zinit as follows:

zinit wait"0b" lucid light-mode for \
  id-as'fzf' \
    as"program" \
    from"gh-r" \
    nocompile \
+   atload"source <(fzf --zsh)" \
    @junegunn/fzf

zinit wait"0c" as"completion" light-mode lucid for \
-     id-as'zsh-completions' @zsh-users/zsh-completions \
+     id-as'zsh-completions' @zsh-users/zsh-completions
-     id-as'fzf-completion' mv'fzf-completion -> _fzf' https://github.com/junegunn/fzf/blob/master/shell/completion.zsh

zinit wait"0d" lucid light-mode for \
-     id-as"fzf-keybindings" https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh \
    id-as'fzf-tab' @Aloxaf/fzf-tab

Note: Updated based on #4211 (comment)

@junegunn
Copy link
Owner

Good to hear that you sorted it out. I'll leave this open until I release the next version in case others run into the same issue.

@junegunn
Copy link
Owner

Note: Not sure if atinit is the best choice here

Shouldn't it be atload?

@junegunn
Copy link
Owner

zdharma-continuum/zinit#697

@sum-elier
Copy link
Author

Note: Not sure if atinit is the best choice here

Shouldn't it be atload?

You are right. Not sure why when I tested atinit worked. I tested it first with atload, did exec zsh --login and worked. Tried atinit with exec zsh --login and it worked too so I defaulted to the most eager option. But now that I tested again by opening a new terminal window, it failed because it couldn't find fzf.

Thank you. I'll update my previous comment.

@junegunn junegunn added the tip label Jan 30, 2025
@Gerrit-K
Copy link

Gerrit-K commented Jan 30, 2025

Not sure whether it makes a huge difference, but I would suggest to use atclone/atpull instead of atload to reduce the impact on shell load time. I've just tried with this and it seems to work for me:

zinit from'gh-r' pick'/dev/null' for \
 atclone'./fzf --zsh > __fzf__.zsh' \
 atpull'%atclone' \
 src'__fzf__.zsh' \
    sbin'fzf' junegunn/fzf

Edit: removed the chmod as suggested below

@junegunn
Copy link
Owner

Thanks. Yes, reading static script files should be faster than running fzf --zsh. It's up to each one to decide if the extra step is worth it.

$ hyperfine 'zsh -ci "source shell/key-bindings.zsh; source shell/completion.zsh"' 'zsh -ci "source <(fzf --zsh)"'
Benchmark 1: zsh -ci "source shell/key-bindings.zsh; source shell/completion.zsh"
  Time (mean ± σ):       8.5 ms ±   0.2 ms    [User: 5.3 ms, System: 2.5 ms]
  Range (min … max):     8.1 ms …   9.9 ms    255 runs

Benchmark 2: zsh -ci "source <(fzf --zsh)"
  Time (mean ± σ):      12.1 ms ±   0.2 ms    [User: 7.0 ms, System: 4.3 ms]
  Range (min … max):    11.7 ms …  12.7 ms    212 runs

Summary
  zsh -ci "source shell/key-bindings.zsh; source shell/completion.zsh" ran
    1.43 ± 0.05 times faster than zsh -ci "source <(fzf --zsh)"

FWIW, I don't think chmod +x is required as you're not executing, but just sourcing the file.

@Gerrit-K
Copy link

Ah, you're right 👍 I copied this from another plugin where I used this (probably without needing it there as well). I've removed it from my comment. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants