How to search and replace an unprintable character

后端 未结 3 1301
遥遥无期
遥遥无期 2020-12-16 10:57

I\'ve a file that was exported from Word and it replaced all quotes with strange unicode characters which aren\'t correctly displayed in vim. So now I want those characters

相关标签:
3条回答
  • 2020-12-16 11:34

    I usually:

    1. delete the character with: x
    2. undo my change with: u
    3. do the substitute thanks to c_CTRL-R: :%s/^R"/'/g
    0 讨论(0)
  • 2020-12-16 11:47

    you can also filter it by using the tr command

    for example replacing the hex a0 which stems from MacOs cut-and-paste can be replaced with a whitespace as follows (\240 being the octal representation of hex a0)

    :.,$!tr "\240" " "
    
    0 讨论(0)
  • 2020-12-16 11:48

    You can try setting the encoding type and see if it fixes the visalizations of those characters:

    :set encoding=utf-8
    

    then you can use them directly. Alternatively, you can place your cursor on the unprintable character and hit ga, it will show the decimal/hex/octal code of that character, then you can substitute it with:

    :%s/\%xYY/substitute/g
    

    where YY is the hex code of the char, if it's multibyte:

    :%s/\%uYYYY/substitute/g
    

    for details:

    :help character-classes
    

    Note that you can search and match with \%xff or \%uabcd but will be unable to substitute with it.

    0 讨论(0)
提交回复
热议问题