36

Couldn't figure this out. Just need to enter 1 emoji into a string and couldn't figure it out. Unicode is not working. Tried diagraph but didn't work either. Is there some trick to this in Vim? thx!

DC Slagel
  • 528
  • 1
  • 7
  • 13
Fedreg
  • 523
  • 2
  • 6
  • 15
  • http://junegunn.kr/2014/06/emoji-completion-in-vim/ – Kent Oct 26 '16 at 13:00
  • thanks. Was hoping for a way to just enter it without adding a whole plugin. Not that big of a deal to add a plugin just seems like there has to be another way. – Fedreg Oct 26 '16 at 13:03

5 Answers5

46

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)

DJMcMayhem
  • 7,285
  • 4
  • 41
  • 61
  • 1
    I succeeded entering a smiley face per your example. But I am trying to enter ❤️, which comes up with two code points, "U+2764, U+FE0F". Not sure how to enter that! – Dmitry Minkovsky Apr 08 '20 at 03:50
22

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.

bitifet
  • 3,514
  • 15
  • 37
  • 1
    Nice; the [following answer](https://stackoverflow.com/a/57027637/211827) links specifically to [emoji-ab](https://gitlab.com/gi1242/vim-emoji-ab), and this essentially mirrors what I [utilize system-wide for replacements](https://ghcdn.webcore.io/mac/system-wide-text-replacements.png). – amcgregor Nov 22 '21 at 16:54
  • So looks like I reinvented the wheel again :-D. Thanks for the report @amcgregor – bitifet Dec 26 '21 at 22:09
5

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:

  1. Type your usual smileys like :) and have a plugin replace it with the unicode equivalent . The plugin emoji-ab does this for you.

  2. 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.

  3. Use something like gucharmap (or one of the many online Unicode pickers) to copy and paste unicode characters into vim.

gi1242
  • 51
  • 1
  • 2
5

Another way to access these emojies in many contexts including Vim is to use the character map dialog window:

  • On Mac, press Ctrl+Command+Space and select the character.
  • On Windows, press Windows+R and type the charmap.

Charmap selector image

ib.
  • 27,830
  • 11
  • 80
  • 100
Mickey Pashov
  • 51
  • 3
  • 4
  • GNOME 3.28 and above (Ubuntu Linux and elsewhere) has an emoji picker, but sadly it doesn't work in GNOME Terminal. See https://www.omgubuntu.co.uk/2018/06/use-emoji-linux-ubuntu-apps – Flimm Dec 31 '20 at 16:31
2

You can use emoji-fzf pip package

First install fzf

sudo apt install fzf 

then intall emoji-fzf

pip install emoji-fzf

now make sure you can run emoji-fzf

emoji-fzf --help

if you get "comand not found" error please see pip installs packages successfully, but executables not found from command line

now add emoji-fzf to your .vimrc

" Use emoji-fzf and fzf to fuzzy-search for emoji, and insert the result
function! InsertEmoji(emoji)
    let @a = system('cut -d " " -f 1 | emoji-fzf get', a:emoji)
    normal! "agP
endfunction

command! -bang Emoj
  \ call fzf#run({
      \ 'source': 'emoji-fzf preview',
      \ 'options': '--preview ''emoji-fzf get --name {1}''',
      \ 'sink': function('InsertEmoji')
      \ })
" Ctrl-e in normal and insert mode will open the emoji picker.
" Unfortunately doesn't bring you back to insert mode 
map <C-e> :Emoj<CR>
imap <C-e> <C-o><C-e>

restart your vim and press ctrl + e and search for your favourite emoji and press enter

Mahdi mehrabi
  • 1,486
  • 2
  • 18
  • 21