When writing transliterated Arabic (which looks like this: lammā aktub naṣṣan ʿarabiyyan bi-ḥurūfin lātīniyyah) I sometimes leave off a macron that should go on a vowel (e.g., ā ē ī ō ū), or a dot that should go under a consonant (ḍ ṭ ḥ ṣ ...). Right now I have to type r<option-a> or the like (I'm on a Mac using the American Diacritics keyboard), which is a bit slow and finger-twisting, especially for words with multiple things to fix. Accordingly, I would like to have normal-mode mappings that toggle whether such a letter has a macron or a dot, something like:

nnoremap = {TOGGLE a to ā or back again, as the case may be}
nnoremap <leader>. {TOGGLE d to ḍ or back again, as the case may be}

Where the toggle jumps back and forth some number of steps in the Unicode table.

Is there a simple way to do that in NeoVim?

  • 1
    you might want to try :help digraphs
    – D. Ben Knoble
    Oct 22, 2022 at 20:57

1 Answer 1


You can use a function to do the replacement. The function uses two lists, one with the letters including the diacritics and the other with the letters without them. Note that the indices must match.

The function then looks for the current character in both lists and, when found, returns a command that comprises of r (for "Replace") followed by the character at the matching index at the other list.

So it's suitable for use in a nnoremap <expr> mapping, which will issue the "Replace" command whenever it finds a character that can be toggled.

function! ToggleDiacritics()
  let c = nr2char(strgetchar(getline('.'), charcol('.')-1))
  let dia = ['ā', 'ē', 'ī', 'ō', 'ū', 'ḅ', 'ḍ', 'ḥ', 'ḳ', 'ḷ', 'ṃ', 'ṇ', 'ṛ', 'ṣ', 'ṭ', 'ṿ', 'ẉ', 'ẓ']
  let nor = ['a', 'e', 'i', 'o', 'u', 'b', 'd', 'h', 'k', 'l', 'm', 'n', 'r', 's', 't', 'v', 'w', 'z']
  let i = index(dia, c)
  if i >= 0
    return 'r'.nor[i]
  let i = index(nor, c)
  if i >= 0
    return 'r'.dia[i]
  return ''

nnoremap <expr> <Leader>. ToggleDiacritics()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.