简体   繁体   English

如何在Vim中使用其UTF-8序列键入Unicode字符?

[英]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 . 它的Unicode代码点是U+20a9
In insert mode, I can press Ctrl - V u20a9 to type it. 在插入模式下,我可以按Ctrl - V u20a9键入它。
If I only know its UTF-8 form e2 82 a9 , how can I type it easily? 如果我只知道它的UTF-8格式e2 82 a9 ,我该如何轻松输入?

I just found this solution: 我刚刚找到了这个解决方案

In insert mode, press Ctrl - R ="\\xe2\\x82\\xa9" Enter . 在插入模式下,按Ctrl - R ="\\xe2\\x82\\xa9" 输入

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 现在你可以:UTF8 e2 82 a9

You can also type this particular character with <Ck>W= . 您也可以使用<Ck>W=键入此特定字符。 See :help digraph-table-mbyte . 请参阅:help digraph-table-mbyte

Note that you can also get information about a character with ga and g8 in normal mode. 请注意,您还可以在正常模式下获取有关gag8的角色的信息。 So it might be easier to just do <Cr>="\\xe2\\x82\\xa9" once and then do ga to get the code-point. 因此,一旦执行<Cr>="\\xe2\\x82\\xa9"可能会更容易,然后执行ga以获取代码点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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