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

Should show filename for one file with vimgrep #488

Merged
merged 1 commit into from
May 25, 2017
Merged

Should show filename for one file with vimgrep #488

merged 1 commit into from
May 25, 2017

Conversation

ericbn
Copy link
Contributor

@ericbn ericbn commented May 25, 2017

With vim configured with:

set grepprg=rg\ --vimgrep
set grepformat^=%f:%l:%c:%m

and running the command :grep 'vimgrep' doc/rg.1, the output should be:

doc/rg.1:446:8:.B \-\-vimgrep

but the actual output was:

446:8:.B \-\-vimgrep

Same issue would happen if results only match one file. Ag behaves as expected.

With vim configured with:

    set grepprg=rg\ --vimgrep
    set grepformat^=%f:%l:%c:%m

and running the command `:grep 'vimgrep' doc/rg.1`, the output should
be:

    doc/rg.1:446:8:.B \-\-vimgrep

but the actual output was:

    446:8:.B \-\-vimgrep

Same issue would happen if results only match one file. Ag behaves as
expected.
@BurntSushi
Copy link
Owner

Hmm, I think my original intention was that you'd want to pass --with-filename for this, but I'm guessing that the output of --vimgrep is completely useless if there's no file name, right?

@ericbn
Copy link
Contributor Author

ericbn commented May 25, 2017

The grep command for vim should be only configured as set grepprg=rg\ --vimgrep, right?

Now, the default grep format in vim is (see :help grepformat) "%f:%l:%m,%f:%l%m,%f %l%m", meaning <filename>:<linenumber>:<text> or the variations that follow. Both %f and %l are the minimal elements required for a useful output.

Ag introduced the column number on it's --vimgrep output, requiring the extra set grepformat^=%f:%l:%c:%m configuration (the ^= prepends to the existing default comma-separated list). Vim supports even more configurable elements (see :help errorformat), and having the column number better positions the cursor when browsing the results.

TL;DR yeah, the --vimgrep output is useless without the file names.

@BurntSushi
Copy link
Owner

The grep command for vim should be only configured as set grepprg=rg\ --vimgrep, right?

I don't know. I don't use ripgrep inside of vim.

But I buy it! Thanks!

@BurntSushi BurntSushi merged commit 1e3fc79 into BurntSushi:master May 25, 2017
@ericbn ericbn deleted the vimgrep-with-filename branch May 25, 2017 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants