How to change \\u7f51 to common character in vim?

2019-05-07 12:10发布

问题:

In ruby, since it's utf-8 encoded in the system wide. so it's pretty straight forward:

string = "\u7f51\u5740\u4e0d\u80fd\u4e3a\u7a7a"

=>网址不能为空

Anyone can I tell me that how to do this in vim?

回答1:

If you are wanting to insert Unicode characters, see the utf-8-typing help.

For example, Ctrl-V u7f51 will insert 网.

If you are wanting it in Vim scripts, you can use Unicode escapes in the same way as in Ruby; the command echo "\u7f51\u5740\u4e0d\u80fd\u4e3a\u7a7a" will echo the string you provide in your question.

Being aware of this, Ctrl-R comes into play, with the " and = registers; see the docs for i_CTRL-R and i_CTRL-R_= for more info.

Given the following, with the cursor inside the double-quoted string:

string = "\u7f51\u5740\u4e0d\u80fd\u4e3a\u7a7a"

Apply these keystrokes: ci"Ctrl-R="Ctrl-R""EnterEsc

This will turn it into the following:

string = "网址不能为空"

Try to figure out how it works yourself, but I'll explain more if you can't figure it out.