-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[Feature] Action to change --nth
and --with-nth
dynamically
#3109
Comments
As a workaround you could use the rtf() {
GREP_COMMAND="grep --color=always --line-number . ${@:?Provide at least one argument.}"
FZF_DEFAULT_COMMAND="$GREP_COMMAND | cut -d : -f3-" \
fzf --ansi \
--preview-window 'hidden' \
--bind "ctrl-r:reload:$GREP_COMMAND || true"
} |
Thanks @LangLangBart Edited: |
--nth
and --with-nth
dynamically
Seems to be a duplicate of #2743. Would love this feature ➕ 🤩. I use Fzf as my "primary" search tool: it gets every line of every file, which means I can type all my searches dynamically like in other editors, without having to "pre-think" what the source query is. This works really well, except sometimes I specifically want the search to just filter file content (especially if the content I'm searching for matches a file name!) and other times I want to filter file content and file names e.g. to find usages in some files but not others (like tests). So switching between no filter and "--nth=3" (in my case) would be perfect. Here's a screenshot to illustrate: Here I'm trying to find all occurrences of "influxdb import" in a codebase. As you can see, it's also picking up the file name - again, sometimes I want it to do that - so there are lots of extra results. I know in this case I can just change the query to e.g. "influxdb\ import" or have another command that uses "--nth=3" instead (or try the workaround above), but it would be so much easier if there were an action I could bind to that would just switch to / from "--nth=3" in-place. |
@benthorner There are some strategies you can take to get better results in that case.
|
@junegunn thanks for the suggestions. This is what I usually do but it's not as good as nth:
Normally that would help but I've got What do you think about this proposal? I'm just wondering if there's an architectural reason why this wouldn't work - I haven't looked into the code yet - or just something I've not thought of. |
I'd advise that you remove
I'm not sure about the argument. You can use the search syntax with any type of input, while
fzf is heavily optimized for performance and memory footprint and some parts of the code are not easy to change without compromising the optimizations. Changing |
@junegunn using
Ahh, I forgot about that - thanks!
That makes sense and seems OK if we assume a user would only toggle once per Fzf session; based on my experience, it takes a second or two to reload, which seems reasonable versus starting all over again with In terms of code complexity, it's of course up to you if you think this feature is worth more than the maintenance pain it will create. For me it's a complementary to the other actions and search techniques, giving users a bit more flexibility in how they solve their search problem efficiently - admittedly, it's not really a fuzzy searching problem. @cibinmathew what was your usecase for this, by the way? I realise I'm hogging your issue! |
@benthorner Fair enough.
If that is your goal, you should probably pass the initial search query to the ripgrep process and use fzf only as the secondary filter. Or you can demote fzf to a mere selector interface by using
|
Paths can be hidden but cannot be stripped altogether as it impacts preview tools and actions to open matches. Quickly toggling paths on and off would still need actions for changing dynamically @junegunn Pls let us know if you think this can be taken up sooner in the roadmap |
No, it won't be because of the reason I mentioned above. It's not a trivial task. Allowing dynamic change will likely affect the loading performance as the asynchronous loading thread should constantly check if the option has changed with a locking mechanism. |
Having said that, I also have the issue of the preview window taking too much space sometimes, and it helps to change the size or position of it using # [CTRL-/] up,40% -> hidden -> (default, which is right,50%)
fzf --bind 'ctrl-/:change-preview-window(up,40%|hidden|)' --preview 'cat {}' |
man fzf
)Info
Problem / Steps to reproduce
Add action to change
nth
andwith-nth
value during runtime similar tochange-prompt
actionSample use case:
grep -n . dir1 dir2 dir2 | fzf --delimiter : --with-nth=3.. --preview "cat {1}"
(Prefer this most of the time as displaying the filepath and line number makes it more crowded to fit in the screen).
--with-nth=1..
If I can bind a shortcut to togglewith-nth
value during runtime, it would be very useful to see the file path as well.The text was updated successfully, but these errors were encountered: