Tuesday, January 20, 2015

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

[reordering as inline replies are preferred over top-posting on this
mailing list]

On 2015-01-20 13:33, Bao Niu wrote:
>> An example to replace "hello" with "goodbye":
>>
>> :%s/hello/goodbye/g
>>
>> Suppose you need to replace something with slashes in it.
>> The following attempt to replace "a/b" will NOT WORK:
>>
>> :%s/a/b/goodbye/g
>>
>> However, the following will work:
>>
>> :%s.a/b.goodbye.g
>
> Thank you John, but your advice makes me nervous. Does this dot
> ('.') rule also apply to vimgrep? Or it's only for substitution?
> This must be something that only pros use?

It's not something only for pros, and it works fine with vimgrep as
well as with the ":s" and ":g" commands:

:g@foo@p " print every line containing "foo", :g/foo/p
:vimgrep #\<for\># *.py
:%s!/foo/bar!/this/that!g

However, using a regexp meta-character such as "." does give me pause
I tend to fall back to one of "!", "@", or "#" depending on whether
any of them will appear in my regexp because none of them have
inherent meaning in a regexp, unlike the "." which means "any one
character".

-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:

Post a Comment