Creating that special character in vim

... digraphs to the rescue

Posted by geoffm on Thursday, April 30, 2015

Entering special characters into vim

I use vim as my editor. Despite this first sentence, this is not a beginning volley to an editor flame war. I will save that for another day.

Ever editor has its own unique features and vim definitely no stranger to that group. One feature I use quite a bit is what vim calls digraphs.

There are thousands of characters other than the standard keyboard character that can be displayed with vim. You may already know that you can use CTRL-v <enter> to force a linefeed into even a DOS filetype. Actually `CTRL-v ascii### will force special characters from a long list of choices.

But I prefer using CTRL-K followed by two semi-meaningful (slightly resembles the intended special character) to create any one of literally thousands of special characters.

If you are in vim and you are not in INSERT mode (hit ESC a couple of times to make sure) you can type :digraphs and see the first page of possible choices. This list is extensive and daunting when first viewed. It is really sets of 3 columns. The first column is the digraph CTRL-k combo to create what is seen in the second column. And the 3rd column is the CTRL-v ### number to be used to create that same character.

Let’s look at an example - the first column 11 rows down you should see the way to create the one cent character:

Ct ¢ 196 

What this tells you is that if you are in the INSERT mode (Esc Esc i) Then you can type either of these two commands to create a one cent symbol

CTRL-k Ct
# or
CTRV-v 196

If your scroll down the :digraph list you will find just about any special character you can imagine.

BTW - to see what values correspond to a char - cursor to it and hit :as[cii]

Here are a few examples:

CTRL-k 34 = ¾
CTRL-k 12 = ½
CTRL-k -< = ←
CTRL-k -> = →
CTRL-k -v = ↓
CTRL-k -! = ↑
CTRL-k <> = ↔
CTRL-k => = ⇒
CTRL-k OK = ✓
CTRL-k -X = ✠
CTRL-k XX = ✗
CTRL-k <' = 「
CTRL-k >' = 」
CTRL-k Fm = ♀
CTRL-k Ml = ♂
CTRL-k *1 = ☆ 
CTRL-k *2 = ★
CTRL-k D* = Δ

Enjoy
-g-
comments powered by Disqus