How to Type Special Characters in Vim
Contents
Introduction
How to type special characters in Vim? Usually, my solution was to copy-paste it from the browser. For such an infrequent use, this was enough.
I recently embarked on a journey to learn Spanish, where one has to frequently type accent graves (á, é, ñ, etc.) and upside down punctuations (¡Estupendo!, ¿Que?).
The copy-paste method get repetitive and slowed down my workflow.
I looked up whether there was a faster or proper way to type special characters in Neovim. And, there is!
Using Character Value
Each character has a terminal code, or a decimal, octal, or hexadecimal value.
Vim has a built in method where we can use any of the character value to print that character.
In insert mode, press CTRL V followed by the <value>
.
For e.g., CTRL V followed by <163>
prints the symbol for pound (£999).
We can use the hexadecimal value, for e.g., CTRL V followed by xb0
prints the character for degree (100°C).
Description | Character | Decimal | Hexadecimal |
---|---|---|---|
Pound | £ | 163 | 0xa3 |
Copyright | © | 169 | 0xa9 |
Registered | ® | 174 | 0xae |
Degree | ° | 176 | 0xb0 |
Plus-minus | ± | 177 | 0xb1 |
Superscript two | ² | 178 | 0xb2 |
Using Digraph
Each character also has a digraph value.
In insert mode, press CTRL K followed by the two-letter <digraph>
.
For e.g., CTRL K followed by a’ gives us ‘á’.
Alternative, enable the ‘digraph option’ with :set digraph
or :set dg
.
Then we can do, for e.g., : then BS (backspace), and a, which will give us ‘ä’.
To list all defined digraphs, use the command :digraphs
or :dig
.
Character | Digraph |
---|---|
ø | o/ |
≥ | >= |
≮ | !< |
≠ | != |
√ | RT |
× | /\ |
÷ | -: |
Character | Digraph |
---|---|
⊂ | (C |
⊃ | )C |
∩ | (U |
∪ | )U |
⅗ | 35 |
₂ (sub) | 2s |
³ (sup) | 3S |
Character | Digraph |
---|---|
á | a’ |
Á | A’ |
è | e` |
î | i^ |
ö | o: |
ç | c, |
ñ | n~ |
Š | S< |
Character | Digraph |
---|---|
α | a* |
Α | A* |
β | b* |
Β | B* |
γ | g* |
Γ | G* |
Note: Digraphs for Greek alphabets always follow a ’*‘.
Digraphs are fairly intuitive, and easier to type than character codes.