vimunicodevimgrep

(VIM) Is vimgrep capable of searching unicode string


Is vimgrep capable of searching unicode strings? For example:

a.txt contains wide string "hello", vimgrep hello *.txt found nothing, and of course it's in the right path.


Solution

  • "Unicode" is a bit misleading in this case. What you have is not at all typical of text "encoded in accordance with any of the method provided by the Unicode standard". It's a bunch of normal characters with normal code points separated with NULL characters with code point 0000 or 00. Some Java programs do output that kind of garbage.

    So, if your search pattern is hello, Vim and :vim are perfectly capable of searching for and finding hello (without NULLs) but they won't ever find hello (with NULLs).

    Searching for h^@e^@l^@l^@o (^@ is <C-v><C-@>), on the other hand, will find hello (with NULLs) but not hello (without NULLs).

    Anyway, converting that file/buffer or making sure you don't end up with such a garbage are much better long-term solutions.