How to grep #tag?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to grep #tag?

Lifepillar
How can I grep text with a special symbol, such as #?

I would like to search a bunch of files containing various #tags, but if
I try from the command line:

    :grep #sometag

that does not work. Escaping the hash causes grep to exit with an error:

    :grep \#sometag

Any idea?

Thanks,
Life.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/rlt7u6%24r9b%241%40ciao.gmane.io.
Reply | Threaded
Open this post in threaded view
|

Re: How to grep #tag?

Shlomi Fish-2
Hi, Life!

On Sat, 10 Oct 2020 21:09:26 -0000 (UTC)
Lifepillar <[hidden email]> wrote:

> How can I grep text with a special symbol, such as #?
>
> I would like to search a bunch of files containing various #tags, but if
> I try from the command line:
>
>     :grep #sometag
>
> that does not work. Escaping the hash causes grep to exit with an error:
>
>     :grep \#sometag
>

Either:

        :grep \\#p

Or:

        :grep '\#p'

Seem to work here in gvim (Linux; shell is either bash or zsh).

> Any idea?
>
> Thanks,
> Life.
>



--

Shlomi Fish       https://www.shlomifish.org/
The Case for File Swapping - https://shlom.in/file-swap

SGlau: shut up, Mr. Frog! I’m here on a mission from the Grammar God. Herr
Norris and I are loyal servants of Grammar Nazism, which aims to unite Grammar
Europe under the reign of the Third Grammar Reich. Hail Grammar!
    — https://is.gd/htmOCv

Please reply to list if it's a mailing list post - https://shlom.in/reply .

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20201011081112.27473f84%40telaviv1.shlomifish.org.
Reply | Threaded
Open this post in threaded view
|

Re: How to grep #tag?

Lifepillar
On 2020-10-11, Shlomi Fish <[hidden email]> wrote:

> On Sat, 10 Oct 2020 21:09:26 -0000 (UTC)
> Lifepillar <[hidden email]> wrote:
>
>> How can I grep text with a special symbol, such as #?
>
> Either:
>
> :grep \\#p
>
> Or:
>
> :grep '\#p'
>
> Seem to work here in gvim (Linux; shell is either bash or zsh).

That does it! Double-escaping is always tricking me.

Thanks,
Life.


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/rlumj5%2415f7%241%40ciao.gmane.io.
Reply | Threaded
Open this post in threaded view
|

Re: How to grep #tag?

Bram Moolenaar

> On 2020-10-11, Shlomi Fish <[hidden email]> wrote:
> > On Sat, 10 Oct 2020 21:09:26 -0000 (UTC)
> > Lifepillar <[hidden email]> wrote:
> >
> >> How can I grep text with a special symbol, such as #?
> >
> > Either:
> >
> > :grep \\#p
> >
> > Or:
> >
> > :grep '\#p'
> >
> > Seem to work here in gvim (Linux; shell is either bash or zsh).
>
> That does it! Double-escaping is always tricking me.

You can use any special character to surround the pattern, it's a lot
easier than escaping.  I often use ":grep /pattern/ *", unless the
pattern contains a slash.

--
I'm trying to be an optimist, but I don't think it'll work.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/202010111222.09BCMkFq3991128%40masaka.moolenaar.net.
Reply | Threaded
Open this post in threaded view
|

Re: How to grep #tag?

LuKreme
On 11 Oct 2020, at 06:22, Bram Moolenaar <[hidden email]> wrote:
> You can use any special character to surround the pattern, it's a lot
> easier than escaping.  I often use ":grep /pattern/ *", unless the
> pattern contains a slash.

As soon as I learned you could use any delimiter you wanted I stopped using / and switched to | as I never have to escape pipes.

> --
> I'm trying to be an optimist, but I don't think it'll work.

--
No sense being pessimistic. It wouldn't work anyway.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/B8FD884E-B192-4F24-AC17-2E7976716455%40kreme.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to grep #tag?

Lifepillar
On 2020-10-11, @lbutlr <[hidden email]> wrote:
> On 11 Oct 2020, at 06:22, Bram Moolenaar <[hidden email]> wrote:
>> You can use any special character to surround the pattern, it's a lot
>> easier than escaping.  I often use ":grep /pattern/ *", unless the
>> pattern contains a slash.

> As soon as I learned you could use any delimiter you wanted I stopped
> using / and switched to | as I never have to escape pipes.

You still need to escape # inside the pattern, don't you? As in:

    :grep /\#foo/ *

At least, when 'grepprg' is grep (which is the default?). If it's set to
internal, then I can actually search for /#foo/.

Btw, as I was experimenting with grep commands, I have also realised
that a command with -complete=file expands #, but a command without it
does not. So, this is what I've come up with:

    command! -nargs=+ Grep call s:grep(<q-args>)

    fun s:grep(args)
      execute 'silent grep!' shellescape(fnameescape(a:args)) '**/*'
    endf

Then, s:grep() will receive '#foo' when I type :Grep #foo. Inside the
function, fnameescape() will escape # again for :grep!, and
shellescape() will escape the input for the shell. I have yet to test
this thoroughly, maybe there are better ways.

The drawback is that the custom command does not expand any path.

Life.

>> --
>> I'm trying to be an optimist, but I don't think it'll work.
>
> --
> No sense being pessimistic. It wouldn't work anyway.
>
> --

--
It's worse than that. It makes things fall apart.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/rlv4k6%24ks9%241%40ciao.gmane.io.
Reply | Threaded
Open this post in threaded view
|

Re: How to grep #tag?

arocker

If we're talking about shell grep, it's wise always to quote the search
string, (which kind of quote is preferable depends on which OS/shell),
whether it has special characters or not. If it's redundant, no harm done.
If it isn't, you don't have to guess how the shell molested your string

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/0ea623769ce2e76cbec7c31d04f6f191.squirrel%40webmail.vybenetworks.com.