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 | |||
ha |
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:
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:
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!