Sunday, October 11, 2020

Re: How to grep #tag?

On 2020-10-11, @lbutlr <kremels@kreme.com> wrote:
> On 11 Oct 2020, at 06:22, Bram Moolenaar <Bram@moolenaar.net> 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 vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/rlv4k6%24ks9%241%40ciao.gmane.io.

No comments: