Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

ignore filenames in grep module #84

Merged
merged 1 commit into from
Mar 13, 2021

Conversation

purxiz
Copy link
Contributor

@purxiz purxiz commented Mar 12, 2021

This commit makes it so that fzf ignores the filenames and line numbers in the recursive grep module. I really couldn't find a nicer place to add these fzf-args, but I'm very open to fixing this PR with feedback from whoever. Basically fzf requires all grep tools to return filename:line_number:text, so we can ignore filename and line number with a column delimiter and then only looking from column 3 onward.

This commit makes it so that fzf ignores the filenames and line numbers in the recursive grep module. I really couldn't find a nicer place to add these fzf-args, but I'm very open to fixing this PR with feedback from whoever. Basically fzf requires all grep tools to return filename:line_number:text, so we can ignore filename and line number with a column delimiter and then only looking from column 3 onward.
@andreyorst
Copy link
Owner

fzf.kak uses filename and line number information to jump, if we ignore it, the jump is impossible. But applying your patch I can't see what is actually changed, so I'm not sure what is the impact and what problem you're trying to solve? Can you elaborate a bit more on this?

with this patch:
image

Without:
image

From the manpage for fzf I see that

   --with-nth=N[,..]
          Transform the presentation of each line using field index expressions

   -d, --delimiter=STR
          Field delimiter regex for --nth and --with-nth (default: AWK-style)

But we don't use --with-nth in this plugin, so --delimeter seems not to have any effect. I assume that you have some local configuration, that sets the with-nth parameter, and I don't have it, so that's why I don't see any difference?

@purxiz
Copy link
Contributor Author

purxiz commented Mar 13, 2021

Hi, --with-nth is the same as -n, which I have added to the config. Here's the relevant flags I've added for the grep module:

--delimiter=':' -n'3..'

Let's say you are in this project, and you try searching for the line fzf in :fzf-mode<g> (grep module, without my patch). Your results would be:

image

Since the program is currently considering the entire string returned by grep/ripgrep/etc., if you search for a phrase contained in a filename, you will get a bunch of results, equal to the number of lines in that file. With my patch, searching for fzf in the grep module only returns results where fzf is in the actual document text, as you would expect from a normal recursive grep:

image

The string and filename are still in the results, so jumping using them is still possible, but they are ignored by fzf for searching purposes, so you don't get a ton of duplicate results if there is a filename matching your search string. You can read a similar issue in the vim fzf repo: junegunn/fzf.vim#346.

Overall, this only affects the functionality of the grep module, and makes it so it actually only greps, instead of also searching by filename and returning a ton of results.

@andreyorst
Copy link
Owner

Ah, I see, thanks for explanation. Yeah, this is definitively useful change! I think I can use it in some other modules as well

@andreyorst andreyorst merged commit 2ff1246 into andreyorst:master Mar 13, 2021
@purxiz purxiz deleted the ignore_filenames_grep branch March 13, 2021 20:39
@andreyorst
Copy link
Owner

@purxiz Thanks for the tip! If you use fzf-project it will now also ignore paths, and use projcect names as match candidates only!

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

Successfully merging this pull request may close these issues.

2 participants