Vim logo

One of the great features of Chakra Darshana is that it tries to provide authentic spelling of all Sanskrit terms that appear in the user interface. Fortunately, Vim - the editor that we use for development - makes it very easy to type Sanskrit transliteration. In this blog post, we explore what is available for Sanskrit in Vim out of the box and share what needs to be customized in order to make Sanskrit editing a joyful experience.

There are many transliteration schemes for Sanskrit, but the most widely used and the most readable, albeit a bit more complicated to type, is International Alphabet of Sanskrit Transliteration (IAST). Let us remind ourselves how the Sanskrit alphabet looks in IAST:

Sanskrit letters
a ā i ī u ū
e ai o au
ka kha ga gha ṅa
ca cha ja jha ña
ṭa ṭha ḍa ḍha ṇa
ta tha da dha na
pa pha ba bha ma
ya ra la va
śa ṣa sa

It can be seen that some Sanskrit letter transliteration can be represented using plain ASCII, some can be easily typed using conventional keyboards (like pressing Alt + a for ā in Latvian), but other letters with diacritics like ś are not usually found in languages we commonly use.

Fortunately, the digraph facility in Vim solves the problem. A digraph means that we can use two characters, preceded by Ctrl + K, to represent one character. If we look at the list of digraphs that are available in Vim by default using :digraphs, we will see the following output:

...    S' Ś  346    s' ś  347    ...

This means that in the example above we can type Ctrl + K s ' to obtain the letter ś or Ctrl + K S ' to obtain the capital version Ś. Some other letters are also available in the default set of digraphs that comes with Vim. However, other digraphs that we need for Sanskrit transliteration are missing, so we have to add them manually using the :digraph command.

For that, we use the following sanskrit.vim script that is sourced from ~/.vimrc on Vim startup:

" digraph A-  256 " Ā
" digraph a-  257 " ā
" digraph I-  298 " Ī
" digraph i-  299 " ī
" digraph U-  362 " Ū
" digraph u-  363 " ū
" digraph N. 7748 " Ṅ
" digraph n. 7749 " ṅ
" digraph N?  209 " Ñ
" digraph n?  241 " ñ
" digraph S'  346 " Ś
" digraph s'  347 " ś

digraph R, 7770 " Ṛ
digraph r, 7771 " ṛ
digraph R- 7772 " Ṝ
digraph r- 7773 " ṝ
digraph L, 7734 " Ḷ
digraph l, 7735 " ḷ
digraph L- 7736 " Ḹ
digraph l- 7737 " ḹ
digraph M, 7746 " Ṃ
digraph m, 7747 " ṃ
digraph H, 7716 " Ḥ
digraph h, 7717 " ḥ
digraph T, 7788 " Ṭ
digraph t, 7789 " ṭ
digraph D, 7692 " Ḍ
digraph d, 7693 " ḍ
digraph N, 7750 " Ṇ
digraph n, 7751 " ṇ
digraph S, 7778 " Ṣ
digraph s, 7779 " ṣ

The commented entries in the upper part of the script list the digraphs available in Vim by default (note that ñ can also be entered as Ctrl + K n ~) and the statements in the lower part introduce the missing digraphs. The case of the output letter depends on whether a lowercase or uppercase letter is used in the digraph sequence.

Please note that in the script above we gave the , character a different meaning than it has by default in Vim and RFC 1345, which Vim digraphs are based upon. Normally, the , character would add a cedilla to the character preceding it in the digraph sequence, but since ģ and ķ in Latvian can be typed more conveniently using Alt + g and Alt + k, and since . adds a dot above, we decided to use , for adding a dot below for convenience. According to RFC 1345, the suggested mnemonic to add a dot below would be to use a longer sequence - ., making it a trigraph, but it does not look like those are supported in Vim. If you use a language where the cedilla semantics for , are important, you might wish to adapt the script above to better suit your workflow.

Summarizing, if you use the sanskrit.vim script above, the following sequences will give you the necessary characters for IAST transliteration (again, change the case of the letter following Ctrl + K to get the uppercase output):

Sanskrit digraphs
Ctrl + K a - ā Ctrl + K i - ī Ctrl + K u - ū
Ctrl + K r , Ctrl + K r -
Ctrl + K l , Ctrl + K l -
Ctrl + K m , Ctrl + K h ,
Ctrl + K n . Ctrl + K n ? ñ
Ctrl + K t , Ctrl + K d , Ctrl + K n ,
Ctrl + K s ' ś Ctrl + K s ,

Happy Vimming!