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

What does --toggle-sort do? #745

Closed
3 of 15 tasks
kshenoy opened this issue Nov 27, 2016 · 4 comments
Closed
3 of 15 tasks

What does --toggle-sort do? #745

kshenoy opened this issue Nov 27, 2016 · 4 comments
Labels

Comments

@kshenoy
Copy link

kshenoy commented Nov 27, 2016

  • Category
    • fzf binary
    • fzf-tmux script
    • Key bindings
    • Completion
    • Vim
    • Neovim
    • Etc.
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Windows Subsystem for Linux
    • Etc.
  • Shell
    • bash
    • zsh
    • fish

Hi, --toggle-sort is being used in fzf_history but fzf --help doesn't mention what it does.

In fzf_history, why have +s followed by --toggle-sort?

Also, can you please explain what -n does with an example?

@junegunn
Copy link
Owner

junegunn commented Nov 27, 2016

Have you looked at man fzf? More information can be found in the man page. --toggle-sort is kind of deprecated (no plan to remove it though) as it's equivalent to --bind KEYNAME:toggle-sort. We disable sorting with +s (--no-sort) by default to display the commands in chronological order. But sorting can be dynamically enabled by the key specified in --toggle-sort.

-n 2.. (ignoring index number) allows you to perform prefix match on the command for example ^git.

@kshenoy
Copy link
Author

kshenoy commented Nov 28, 2016

Have you looked at man fzf?

No, I didn't even know a man page existed. Thanks for letting me know. That helps but just raises more questions for eg. this bit here: -n2..,... The man page says -n2.. will restrict the search scope to the 2nd to the last field but then there's also ,.. after that increasing the search scope to all fields. Either I'm not following what it does exactly or that seems redundant.

Also, the only thing in there is this line toggle-sort is equivalent to --toggle-sort. It doesn't mention how sorting works. I tried using C-r but that doesn't seem to do anything. Here's an example of the before and after pressing it:

Before:
before-1

After:
after-1

As you can see the order of the command history hasn't changed.

@junegunn
Copy link
Owner

Each comma-separated search scope is tried in order. So fzf first checks if the query matches in 2.. scope, if not, then it searches the whole scope ...

  • ^sudo won't match without 2..
  • 2su won't match without ..
  • ^20 is also valid

See the point?

As you can see the order of the command history hasn't changed.

Try it after typing in some query string. Regarding the ranking algorithm, see https://github.com/junegunn/fzf/blob/0.15.9/src/algo/algo.go#L39

@kshenoy
Copy link
Author

kshenoy commented Nov 28, 2016

Ah, I see. Thanks a lot for answering all my questions.

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

No branches or pull requests

2 participants