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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With