junegunn / fzf

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

Supports quick selection of target item like alfred. #3637

Closed QianChenglong closed 8 months ago

QianChenglong commented 8 months ago

Supports quick selection of target item like alfred. image

image
LangLangBart commented 8 months ago

There is a lesser-known feature in fzf named jump/jump-accept, which closely resembles what is depicted in your screenshots.

To use it, type the command below and press either ; or :, followed by the number next to the item you wish to select.

# '--jump-labels'  is optional
fzf --jump-labels '123456789' --bind ';:jump' --bind '::jump-accept'

Here are some GIFs in a related discussion[^1].


[!NOTE] The maintainer's opinion regarding jump can be found in a related issue.[^2]

[^1]: Discussion on keeping jump characters visible · Discussion #3281 [^2]: Ctrl-c to exit jump and fzf? · Issue #3412

QianChenglong commented 8 months ago

There is a lesser-known feature in fzf named jump/jump-accept, which closely resembles what is depicted in your screenshots.

To use it, type the command below and press either ; or :, followed by the number next to the item you wish to select.

# '--jump-labels'  is optional
fzf --jump-labels '123456789' --bind ';:jump' --bind '::jump-accept'

Here are some GIFs in a related discussion1.

Note

The maintainer's opinion regarding jump can be found in a related issue.2

Footnotes

  1. Discussion on keeping jump characters visible · Discussion #3281
  2. Ctrl-c to exit jump and fzf? · Issue #3412

Thank you very much for your answer. It is very close to the function I want, but the cursor movement and marking cannot be displayed at the same time, which is a bit inconvenient to use.

junegunn commented 8 months ago

Standard terminals don't support CMD-[0-9] or CTRL-[0-9] key chords, but ALT-[0-9] chords are available. The closest you can do is something like this.

ls | awk '{ if (NR <= 5) { print "A-" NR " " $0 } else { print "    " $0 } }' |
  fzf --bind 'alt-1:pos(1),alt-2:pos(2),alt-3:pos(3),alt-4:pos(4),alt-5:pos(5)' | cut -c5-

As per my previous comment, I'm not looking to add a different navigation mode to fzf or to extend the jump mode.