I’ve seen hints on how to search for unicode characters in vim using :help regexp and \%u , but I have not been able to figure out how to replace text with a hex-defined unicode character.
The particular situation is that a DefaultKeyBindings.dict needs comments that will print the character mapped in that line in a comment.
Begin:
blah blah...\U2234
Command:
:s/\v.*\\U(\d{4})/& \/\*\\\\%u\1 \*\/
Result:
blah blah...\U2234 /*\%u2234 */
Goal:
blah blah...\U2234 /* ∴ */
You need to convert the string representation of the hexadecimal Unicode value into the actual character represented by it. This is a task for
nr2char(), which can be embedded into the substitution via:help sub-replace-expression:Protip: Use a different separator (I chose
+over/), then you don’t need to escape.