Vim – entering special character

It’s been a question for me for years, but usually I ignore it. Sometimes, I want to put a special character on my code, for example; a copyright symbol (©) or registered sign (®) or a latin character, or other. Actually it is quiet simple to do using Vim.

First thing to know is RFC1345: Character Mnemonics and Character Sets. You need to know the character mnemonic, then how to put it on your code. Vim provides :digraph. Simply open Vim and type :digraph, you should find a table of special characters which are available in Vim. There are several way of using :digraph, in INSERT mode you can use CTRL+K followed by _two letter combination_, or :set digraph (:set dg), or by entering character value after pressing CTRL+V.

Consider this image:

Vim :digraph

There are three columns described as follow:

1. magenta block (#1): SH, D1, Nb, NH, TS ….

2. green block (#2): ^A, ^Q, #, , , …

3. orange block (#3): 1, 17, 35, 131, 147 …

The first column (#1) represent two letter combination to show the special character in digraph after pressing CTRL+K

The second column (#2) is the special character you want to type

The third columnd (#3) is the character’s decimal value based on RFC1345

See what are the value you need related with REGISTERED SIGN from :digraph extract

Rg  ® 174

So, you can proceed by:

1. CTRL+K Rg

2. CTRL+V 174

3. R <BS> g

For option #3, this can only work when you :set digraph (or :set dg)

<BS> is CTRL+H in Vim

For complete reference, you can see Vim: digraph documentation