Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
772 views
in Technique[技术] by (71.8m points)

vim - How to search and replace an unprintable character

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...