Reputation: 89113
I've got a file that has escaped unicode in it:
blah blah blah \u2192 blah blah blah
I'd like to transform the unicode escapes into actual characters with a search/replace:
:%s/\\u\(\d\{4}\)/\=CodePointToCharacter(submatch(1))/g
Though I know how to transform a codepoint to a character in insert mode (CTRL-V u 2192
for →), I don't know how to do the transformation in a vimL expression.
Do I need to write a custom function, or is there a builtin or plugin I can use?
Upvotes: 3
Views: 191
Reputation: 195229
you can first use str2nr()
to convert the number from HEX, then use nr2char
to display the char.
extend your command a little bit:
%s/\\u\(\x\{4}\)/\=nr2char(str2nr(submatch(1),16))/g
Upvotes: 6