September 24, 2020
You may already be aware of digraphs, which let you insert special characters using combinations of two keys (:h digraphs-use
).
However, Vim also lets you insert arbitrary Unicode characters, as long as your font/terminal emulator supports them.
That includes emoji.
When you’re in insert mode, you can type <c-v>
(or <c-q>
), followed by a letter specifying the format of the number representing the character.
The letters are:
255
o
/O
: octal 3-digit value, max 377
(same as 255 in decimal)x
/X
: hex 2-digit value, max ff
(same as 255 in decimal)u
: hex 4-digit value, max ffff
(same as 65535 in decimal)U
: hex 8-digit value, max 7fffffff
At any point, you can enter a non-digit (such as space or escape) to finish inserting the character, and whatever you entered until that point will be interpreted.
For more info, look at :h i_ctrl-v_digit
.
As an example, let’s say I want to enter the Arabic Bismillah ligature, which is one of the widest I’ve ever seen.
I’ll search the Unicode Character Table, where I’ll find that its value is 0xFDFD
.
Then, in Vim, I’ll enter insert mode, and type: <c-v>ufdfd
(u
for 4-digit hexadecimal; I could also use U
and press space/escape after the last d
).
Et voila: ﷽ (yep, that’s one character).
Another example: what if I want a “no mobile phones” pictograph?
Again, after searching the table, I’ll find that the value is 0x1F4F5
.
So, in Vim, I’ll go to insert mode and type: <c-v>U1f4f5<space>
(U
for 8-digit hex, <space>
to mark the end of the character).
And there we have it: 📵.
As an aside, you can find out the Unicode value of the character under the cursor by typing ga
in normal mode, or using the :ascii
ex command.
If you’re more used to Latex, a useful plugin is latex-unicoder.vim, which converts a typed Latex command to its corresponding Unicode symbol (if there is one).