The \%u
expression is only a valid syntax for the pattern of a search or of a :s
, and not for the replacement part. See :help /\%u
.
Similarly to other search pattern syntax such as \s
to match whitespace, *
to match repeats of the previous item, etc.
In order to produce this character on the replacement side, you have a few options. One of them is to just type the character, assuming you have a keyboard driver that is able to produce it.
From Vim, you can produce that character from its Unicode by using the Ctrl+V combination followed by a sequence of digits, which you can precede with u followed by four hexadecimal characters to enter an Unicode code point.
In your case, Ctrl+V, u, 4, f, 6, 0 will produce the 你 character in either insert or command mode (you need it in command mode to enter it as part of a replacement in a :s
command.)
Note that you would type:
:%s/you/Ctrl+Vu4f60/g
But what you would see is:
:%s/you/你/g
The Ctrl+V sequence is simply being used to enter a Unicode character literally.
The other option you have is to have your replacement start with \=
in order to introduce an expression and then use a \u
escape sequence inside a double quoted string. See :help sub-replace-expression
and :help expr-quote
. Putting that together:
:%s/you/\="\u4f60"/g
The downside of this approach is that you need to turn your whole replacement into an expression, so if you have more characters as part of that replacement, you need to incorporate them into the string. Also, using special items in the replacement, such as &
to repeat the matched pattern, or \1
etc. to insert the contents of matched groups, now requires you to explicitly use the submatch()
function in the expression.
\%u4f60
is a regex atom, that is only valid in the search part of the:s
.