How do I enter an emoji into a string in Vim?
While it is possible to <c-v>U1f60A<esc>
, it's not practical if you're
responding to email / entering a comment in a web form. I'm not going to
memorize unicode emoji tables ðð«ð for quick "Thanks ð" comment.
Few other options for such use cases:
Type your usual smileys like
:)
and have a plugin replace it with the unicode equivalent ð. The plugin emoji-ab does this for you.Type codes like
:boom:
. Many markdown parsers will convert it to ð¥ for you. But if you're not using such a parser, emoji-ab will also convert it for you.Use something like gucharmap (or one of the many online Unicode pickers) to copy and paste unicode characters into vim.
You do not need to install a plugin for this. All you need to do is enter the unicode value of the emoji. You can do that in insert mode with <C-v>
. From :h i_ctrl-v_digit
:
*i_CTRL-V_digit*
With CTRL-V the decimal, octal or hexadecimal value of a character can be
entered directly. This way you can enter any character, except a line break
(<NL>, value 10). There are five ways to enter the character value:
first char mode max nr of chars max value ~
(none) decimal 3 255
o or O octal 3 377 (255)
x or X hexadecimal 2 ff (255)
u hexadecimal 4 ffff (65535)
U hexadecimal 8 7fffffff (2147483647)
For example, if you want to enter this smiley-face, which has a unicode value of U+1F60A
, you could simply type:
<C-v>U1F60A<esc>
or if you don't want to hit <esc>
,
<C-v>U0001F60A
Just so you know, there's a good chance that it will not render properly in vim, depending on your font. If you are using gvim, you can change :se guifont=*
, or in regular vim, changing your consoles font to make it render (assuming you pick a font that can render this particular emoji)
Another approach is to use abbreviations.
I added a few in my .vimrc file and now I just type :pushpin: for ð, :bulb: for ð¡, :bomb: for ð£, etc...
" Emoji shortcuts
ab :white_check_mark: ✅
ab :warning: ⚠
ab :bulb: ð¡
ab :pushpin: ð
ab :bomb: ð£
ab :pill: ð
ab :construction: ð§
ab :pencil: ð
ab :point_right: ð
ab :book: ð
ab :link: ð
ab :wrench: ð§
ab :info: ð
ab :telephone: ð
ab :email: ð§
ab :computer: ð»
There are a lot more of them on emojicopy.com or similar sites. I just picked a few I already used before.