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
feat(defaults): use ripgrep (rg) for 'grepprg' if available #28324
Conversation
I would recommend a new section on "optional tools" that checks
output. (We can extend this later with |
Have adjusted the documentation, turned off the default filtering (with a note in the documentation hinting the user they may want to re-enable it if they wish), and added a rudimentary healthcheck. |
I have overhauled the documentation as requested. I've kept the health check in the proposed 'External Tools' section for now. |
2c340f6
to
8678e3c
Compare
Needs a |
For vim-diff, which section? For news.txt, is this |
I'd say
I'd say to the "Defaults:" list under |
Added. For the sake of brevity I did not include the full default value, since both places link to the option where it's documented. |
Happy to have landed this! Thank you for the feedback and advice. |
Thanks for this! The PR description and the context is useful, be sure to add that to the commit message as well next time :) |
if vim.fn.executable('rg') == 1 then | ||
-- Match :grep default, otherwise rg searches cwd by default | ||
-- Use -uuu to make ripgrep not do its default filtering | ||
vim.o.grepprg = 'rg --vimgrep -uuu $* ' .. (vim.fn.has('unix') == 1 and '/dev/null' or 'nul') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the late review, but what is the rationale for -uuu
rather than -uu
? Is this strictly for compatibility with grep
(which also searches binary files by default)?
Omitting binary file matches strikes me as a better default for a text editor. If the concern is consistent behavior for both rg
and grep
, I'd suggest adding -I
to the default grepprg
to ignore binary file matches in all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes rg -uuu matches grep -r. I do agree that omitting binary files would be better. The documentation at least points out that the user may wish to adjust the flags used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of /dev/null
here is also unnecessary AFAIK. It's used for grep because some versions of grep (e.g. BSD grep) will try to read from stdin if no file argument is given, so a plain grep foo
will block indefinitely and the /dev/null
argument prevents that.
But ripgrep does not behave that way, and adding /dev/null
here means you cannot use :grep foo
to search for foo recursively (since that expands to rg -uuu foo /dev/null
, which of course returns nothing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ripgrep searches the current directory by default. given it's also recursive by default, the /dev/null placeholder is to be both consistent with regular grep, and to prevent an accidental grep without files from potentially spinning up a lengthy process.
Given the feedback by @gpanders, is it worthwhile to revisit this before 0.10? Either when #23235 is closer to completion, or I could do it this weekend. The change is still very young, so I don't think many people have seen or given feedback on it yet, but I do think the suggestions are worth considering. |
Sure, can still be changed (but also in a 0.10.x, so not a blocker either way). |
Based on feedback from neovim#28324, pass -H and -I to regular grep (available on all platforms officially supported by Neovim), and only pass -uu to ripgrep. This makes :grep ignore binary files by default in both cases.
Based on feedback from #28324, pass -H and -I to regular grep (available on all platforms officially supported by Neovim), and only pass -uu to ripgrep. This makes :grep ignore binary files by default in both cases.
Discussed as an idea in #28296.
Changes the defaults for
'grepprg'
and'grepformat'
to use ripgrep and its--vimgrep
mode, if available on the system.Points discussed in the thread:
:grep
), which the user is free to configure themselves as needed. It adds no additional configuration settings or hooks.executable()
check and two option changes. It is very unlikely that ripgrep will experience breaking changes in its CLI that would necessitate adjusting the code or adding version checking.--vimgrep
format,--smart-case
option). This makes it a promising candidate for a place where Neovim can match the pulse of the community.This is my first PR to adjust core Neovim code, as such there's a few points I am seeking feedback on:
'grepprg'
that points the user toward ripgrep and why they may want to use it. Is it clear enough that this default only takes effect if the user makes sure that therg
binary is found by Neovim?:checkhealth
test, I'm unsure what that should look like.I'm happy to make any necessary adjustments.