Tony Barganski
Tony Barganski

Reputation: 2251

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 = ✓

Upvotes: 6

Views: 7452

Answers (2)

Tony Barganski
Tony Barganski

Reputation: 2251

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.

Upvotes: 8

runar
runar

Reputation: 2857

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.

Upvotes: 1

Related Questions