Search code examples
vimhexvi

How do I search for a special character using the character's code point in vim?


I want to be able to find or replace a character in vi by using the decimal or hex number for a character. Like character 92 for example.

Is this possible?


Solution

  • To just search for the ASCII character with a hex value of 0x5c (which is 92 in decimal), use the search pattern:

    /\%x5c
    

    If you want to search for all occurrences of that character in a file and replace them with another character (or characters), you can enter this command:

    :%s/\%x5c/replacement text/gc
    

    You can, of course, replace 5c with the ASCII hex value of whatever character you wish to replace.

    I found this information here via a google search for "vim replace ascii character"