Closed slashfoo closed 8 years ago
On a general note, wouldn't it make sense to use the "very nomagic" switch to avoid escaping everything? Just prepend \V
to the search term and then only very few characters need escaping (I believe backslash and possibly slash). Try it by typing /\V[ab]. It will match literal [ab]
, but no single a
or b
.
See :h magic
for a table of characters we might want to check.
If we decide to stick to escaping, consider using :h escape()
instead of substituting.
@wellle yeah, I know about the flag, but it makes other things need to be escaped instead, so we're on the same boat. We should either do a literal search, or do a thorough test-through on the mode we choose.
I remember trying very nomagic and found more issues with the search string than the one we have now... don't remember exactly what, though. Could be a false memory. :)
I say try it. If it works everywhere, I'm for it. Especially if it can fix the TODO item at the top of the file.
Until then, this fix totally makes sense. Merged, thanks @slashfoo. Any other characters we should worry about...?
Hm, godlygeek handles this a little different... might be worth a look: https://github.com/godlygeek/vim-files/blob/871454686a5d05f9a84999232fb874fbd7a071f9/plugin/vsearch.vim
same as last patch, this fixes stuff that contain a tilde, we probably need to do this with all the characters that have special meaning, and/or do some sort of global escaping to search for the exact string and not use it as a regular expression.