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

request: option for literal searching #190

Closed
lilyball opened this issue Oct 21, 2016 · 13 comments
Closed

request: option for literal searching #190

lilyball opened this issue Oct 21, 2016 · 13 comments

Comments

@lilyball
Copy link

I use ag -Q (or ag --literal) fairly often to do a literal search across files, since it's so fast and colorizes the output. I'd love to be able to use rg this way, except rg doesn't seem to have any support for literal searching.

@BurntSushi
Copy link
Owner

Indeed it does. It uses the same flag as grep does:

    -F, --fixed-strings        Treat the pattern as a literal string instead of
                               a regular expression.

Note that -F should never be used for performance reasons. Its only use (at the moment) is as a convenience to avoid the need to escape regex meta characters. Eventually, I'd like to support what grep does, which is match any one of a number of literals separated by new lines (which should emerge fairly naturally out of #7).

@lilyball
Copy link
Author

Oh geeze. When I saw -Q didn't work, I looked at the list of flags, but apparently I only looked at the "Less common options" section and ignored the top, thinking that the top was a summary and the longer descriptions beneath had all the flags. But now that I've actually read the section header it's obvious that it's not describing the most common options.

@BurntSushi
Copy link
Owner

Yeah, if you have any suggestions on how to make the docs clearer, I would be happy to hear them. I don't think --help is that great today, and I mostly intended the top section to be options that i thought were either more common or somehow more important, but the categorization is something i came up with willy nilly. Maybe it should have more sections? Or one big one?

@lilyball
Copy link
Author

Honestly, I think the best solution would be to have a manpage. The problem with rg --help is that it's not paged, so you have to scroll up to find what you want, which leads to the problem I had of not even reading the top. But manpages are paged by default, so you start with the top, which should make the most common options much more visible.

@BurntSushi
Copy link
Owner

There is a man page. :-)

In #189, it was suggested to show less on --help, but that has downsides too.

@lilyball
Copy link
Author

There is? Does cargo just not know how to install it?

@BurntSushi
Copy link
Owner

Correct.

@BurntSushi
Copy link
Owner

Yes it does. It uses the standard -F flag that grep uses.

Note that this should never be used for performance reasons. Its only use
is for convenience since you don't need to worry about escaping regex meta
characters.

On Oct 21, 2016 14:23, "Kevin Ballard" notifications@github.com wrote:

I use ag -Q (or ag --literal) fairly often to do a literal search across
files, since it's so fast and colorizes the output. I'd love to be able to
use rg this way, except rg doesn't seem to have any support for literal
searching.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#190, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAb34rbg_mrtnusqX_ufRBpryFdc41sgks5q2QMggaJpZM4Kdd_s
.

@duane
Copy link

duane commented Jan 28, 2017

You should probably stop advertising any compatibility with ag/ack if you don't make an effort to match their arguments.... Why copy from grep when you advertise copying from ag/ack? It makes no sense, and ripgrep is harder to use because of it.

It's also very difficult to find in the man because you don't use 'literal', 'quote', 'exact', or any other terminology people are likely to use. "Fixed strings" is a terrible phrase that can mean anything. What is a non fixed string?

@BurntSushi
Copy link
Owner

BurntSushi commented Jan 28, 2017

@duane Can you please point me to the place where ripgrep advertises "compatibility with ag/ack" so that I can fix it? No such promise is intended. No such promise for grep is intended either. ripgrep does take inspiration from those tools though.

Documentation can always be improved. I'm not perfect.

It's also very difficult to find in the man because you don't use 'literal', 'quote', 'exact', or any other terminology people are likely to use.

"literal" is there: https://github.com/BurntSushi/ripgrep/blob/master/doc/rg.1#L61 --- It's also in the --help output.

FWIW, the -F/--fixed-strings flag is from grep. I'd say people are likely to just try -F and hope it works.

@offero
Copy link

offero commented Nov 15, 2019

The help is pretty large. I spent a minute reading through it and then just searched the internet and came here.

@duane
Copy link

duane commented Jan 27, 2020

The "literal" reference in --help refers to a regular expression, not a literal. Edited to remove snark. The documentation does not seem accurate to me.

Re: ack and ag, it's not clear why this is undesirable—they have a much more approachable interface, and I would be happy to explain why if you indicate interest.

@okdana
Copy link
Contributor

okdana commented Jan 27, 2020

The "literal" reference in --help refers to a regular expression, not a literal.... The documentation does not seem accurate to me.

What is inaccurate about it...?

% rg --help | rg -C2 literal
...
--
             
    -F, --fixed-strings                     
            Treat the pattern as a literal string instead of a regular expression. When
            this flag is used, special regular expression meta characters such as .(){}*+
            do not need to be escaped.
--
...

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

No branches or pull requests

5 participants