如何搜索和替换不可打印的字符 [英] How to search and replace an unprintable character

查看:35
本文介绍了如何搜索和替换不可打印的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从 Word 导出的文件,它用奇怪的 unicode 字符替换了所有引号,这些字符在 vim 中没有正确显示.所以现在我想用引号替换这些字符,但我不知道如何在

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 to be replaced with quotes, but I don't know how to enter this character in

:%s/???/'/g

字符看起来像这样:~U ~R.但当然我不能只用鼠标标记它们并粘贴到命令中.

The characters look like this: ~U ~R. But of course I can't just mark them with mouse and paste in the command.

推荐答案

您可以尝试设置编码类型,看看它是否修复了这些字符的可视化:

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

:set encoding=utf-8

然后就可以直接使用了.或者,您可以将光标放在不可打印的字符上并点击 ga,它将显示该字符的十进制/十六进制/八进制代码,然后您可以将其替换为:

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

其中 YY 是字符的十六进制代码,如果它是多字节的:

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

:%s/\%uYYYY/substitute/g

详情:

:help character-classes

请注意,您可以使用 \%xff\%uabcd 进行搜索和匹配,但将是 无法替代.

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

这篇关于如何搜索和替换不可打印的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆