How to Type Special Characters in Vim

Tags: vim writing 

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).

Example list of few character values:
DescriptionCharacterDecimalHexadecimal
Pound£1630xa3
Copyright©1690xa9
Registered®1740xae
Degree°1760xb0
Plus-minus±1770xb1
Superscript two²1780xb2

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.

Example digraphs for Math symbols:
CharacterDigraph
øo/
>=
!<
!=
RT
×/\
÷-:
CharacterDigraph
(C
)C
(U
)U
35
₂ (sub)2s
³ (sup)3S
Example digraphs for accents:
CharacterDigraph
áa’
ÁA’
èe`
îi^
öo:
çc,
ñn~
ŠS<
Example digraphs for Greek alphabets:
CharacterDigraph
α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.

Comment on this post with email.

Return to Top of the page.
See all Posts.
Subscribe to RSS feed.