简体   繁体   中英

How to type a Unicode character using its UTF-8 sequence in Vim?

is the currency symbol for North Korea. Its Unicode code-point is U+20a9 .
In insert mode, I can press Ctrl - V u20a9 to type it.
If I only know its UTF-8 form e2 82 a9 , how can I type it easily?

I just found this solution:

In insert mode, press Ctrl - R ="\\xe2\\x82\\xa9" Enter .

I'd like to know about any other (shorter?) methods, though.

Same solution with a twist of automation to help remember it:

command! -nargs=* UTF8 call EncodeUTF8(<f-args>)
fun! EncodeUTF8(...)
   let utf8str = ""
   for i in a:000
      let utf8str .= "\\x" . i
   endfor
   exe "norm i" . eval("\"".utf8str."\"")
endfun

Now you can :UTF8 e2 82 a9

You can also type this particular character with <Ck>W= . See :help digraph-table-mbyte .

Note that you can also get information about a character with ga and g8 in normal mode. So it might be easier to just do <Cr>="\\xe2\\x82\\xa9" once and then do ga to get the code-point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM