Monday, January 19, 2015

Re: Should vimgrep always use "/" to enclose your search patterns?

On 2015-01-19 20:24, Bao Niu wrote:
> in Vim is enclosing your search pattern with "/" recommended? The
> documentation says it is optional. If it's optional then why not
> just forget it? Can someone explain this using newbie friendly
> language, preferably with examples. Thanks.

While this is only from my personal experience, I tend to wrap my
pattern in /.../ if it's anything beyond a simple single word. So I
might do

:vimgrep foobar *.c *.h

whereas I'd use

:vimgrep /foo.*bar/ *.c " uses a regexp
:vimgrep /foo bar/ *.c " has a space
:vimgrep /@term@/ *.c " has the same char at the beginning/end

I'm pretty sure (shooting from the hip here, so test to make sure)
that as long as it doesn't have a space in it and it doesn't have
the same non-word character at the start and end of the pattern, it
should be fine to omit them. But rather than think, I just use the
heuristic of "if it's a single word, don't bother; otherwise, wrap
the pattern"

-tim


--
--
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.
For more options, visit https://groups.google.com/d/optout.

No comments: