Inserting a Unicode character in VIM

Published: Tuesday, Jun 10, 2008 Last modified: Monday, Nov 11, 2024

Ok, lets first lookup the character we want with unicode:

x61:~% unicode -r peace
U+262E PEACE SYMBOL
UTF-8: e2 98 ae  UTF-16BE: 262e  Decimal: ☮
☮
Category: So (Symbol, Other)
Bidi: ON (Other Neutrals)

U+4DCA HEXAGRAM FOR PEACE
UTF-8: e4 b7 8a  UTF-16BE: 4dca  Decimal: ䷊
䷊
Category: So (Symbol, Other)
Bidi: ON (Other Neutrals)

The important element is the U+262E part, which is the Unicode codepoint.

Now into insert the PEACE SYMBOL, in INSERT MODE type:

[Ctrl]+[v], [u], [2], [6], [2], [E]

If you can’t see the inserted character, try gvim. Also try place the cursor over the character an use ga shortcut to examine the character underneath the cursor.

ga might report something like:

<?> 9774, Hex 262e, Octal 23056

Understand the Hexadecimal is the key to the codepoint.