Search code examples
vimhexoctaldigraphs

vim - search for a digraph using its octal value


If I have this digraph character: ň in a file, place the cursor over it and type ga I see the message

<&#328;> 328, Hex 0148, Octal 510

But then if I search for /\%o510 or /%x0148 I get E486: Pattern not found

in my vimrc:

set encoding=utf-8 set fileencoding=utf-8

How do I search for these characters using either Octal or Hex codes?


Solution

  • From :help %o:

    %o   Matches the character specified with an octal number up to 0377.
    %x   Matches the character specified with up to two hexadecimal characters.
    

    Because 0510 octal is greater than 0377, the octal search will not match. Similarly, %x admits up to two hexadecimal characters but you need three (148).

    Instead use four-character hex-search:

    %u   Matches the character specified with up to four hexadecimal characters
    

    So the pattern is \%u148