Wednesday, October 23, 2013

Re: Literal Regexes

On Wednesday, 23 October, 2013 at 10:51:23 BST, Tim Chase wrote:
>On 2013-10-23 10:40, Paul wrote:
>> Sometimes I will want to do a simple search and replace on a string
>> that contains characters that I have to escape, eg. for
>> '$foo->{bar}[0]', I would have to use '\$foo->{bar}\[0\]'. I try
>> not to use the various magic types, because it's difficult to
>> remember them, and it's recommended to not change the default magic
>> setting. Is there a way I can do 's/$foo->{bar}[0]/foobar/' and
>> have it not treat any characters as special, ie. treat the search
>> string as all literal?
>
>Mostly. If you include
>
> \V
>
>in your pattern (I usually just put it at the beginning, but I think
>it can go anywhere), it will activate "very no magic" processing.
>This means that only the backslash needs to be escaped, treating
>everything else literally.
>
> :help /\V

Thanks, Tim. I don't know how I missed that in ':help magic', I think all the backslashes in the examples table confused me!

--
--
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/groups/opt_out.

No comments: