Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting unicode characters in vim

I would like a quick and easy way to insert certain unicode characters into text files with vim that I use often, for example, the British Pound Sterling and the tick characters instead of typing:

i C-v u00A3 = £
i C-v u2713 = ✓
like image 554
Tony Barganski Avatar asked May 16 '26 12:05

Tony Barganski


2 Answers

TL;DR

After some digging around, I was able to come up with these:

Digraph Shortlist

Insert Digraphs
i C-k OK = ✓
i C-k $$ = £
i C-k Eu = €
i C-k XX = ✗
i C-k TM = ™
i C-k Co = ©
i C-k Rg = ®
i C-k /- = †
i C-k RT = √
i C-k *1 = ☆
i C-k *2 = ★
i C-k NS =   (non-breaking space)

NB: tmux maps C-k so unmap it for vim in tmux.conf

This new functionality was added to Vim 8.2 released in May 2019.

These are entered from insert mode using C-k <2letter shortcut>

Type :digraph or just :dig to display a list of all possible digraphs in Vim.


P.S.

Not to be confused with diacritics which are character accents like the German umlaut ü.

Hope this helps someone out there too.

like image 101
Tony Barganski Avatar answered May 19 '26 03:05

Tony Barganski


I believe the quickest and simplest way to insert the Unicode code is to add abbreviations for the characters you use most often:

:iabbrev upound <C-v>u00A3
:iabbrev utick <C-v>u2713

These commands adds abbreviations and makes them available in insert mode. To expand them, write the name ("upound" or "utick") followed by a non-keyword character such as comma, space, Esc, or Enter.

like image 31
runar Avatar answered May 19 '26 02:05

runar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!