How can I get vim to render Arabic text correctly?
Asked Answered
C

2

7

I'm learning Arabic and I'd like to use Vim for taking notes. I tried a few different setups on Windows 10 and so far the closest to a good setup seems to be vim in MSYS2. MSYS2 renders Arabic text correctly, written from right to left, but when I open the file in Vim, while the text is still written from the right to left with Arabic characters, the letters are not connected.

Here are a few examples using cat:

سريع
اعتن بنفسك
بطيء
أن تقلق
لا تقلق

And the same ones from Vim:

ﺱﺮﻴﻋ
ﺎﻌﺘﻧ ﺐﻨﻔﺴﻛ
ﺐﻄﻳﺀ
ﺄﻧ ﺖﻘﻠﻗ
ﻻ ﺖﻘﻠﻗ

Looking up the first word of the terminal output on http://unicode.scarfboy.com/ gives me these:

Constituent codepoints:
   0633   ARABIC LETTER SEEN
   0631   ARABIC LETTER REH
   064A   ARABIC LETTER YEH
   0639   ARABIC LETTER AIN

And the codes for the same word in Vim are:

Constituent codepoints:
   FEB1   ARABIC LETTER SEEN ISOLATED FORM
   FEAE   ARABIC LETTER REH FINAL FORM
   FEF4   ARABIC LETTER YEH MEDIAL FORM
   FECB   ARABIC LETTER AIN INITIAL FORM

This looks like it's interpreting the text the wrong way around, the first letter should be in the initial form and the last one should be in its final form.

When I try entering :set arabic, the direction of writing changes for both Arabic and Latin text, making everything backwards, but the characters are rendered correctly (just at the wrong place).

Is there maybe a way to make vim output text the same way the terminal does? Maybe just change which characters are considered first and last, because MSYS2 is outputting the text correctly.

On a side note, my preferred setup would be to use vim in WSL, inside Windows Terminal, but that's not that important as long as I end up with something usable.

Cayman answered 26/2, 2021 at 6:42 Comment(1)
Thanks for asking this -- I just started learning Arabic, and taking notes in Vim sounds awesome. I'm using WSL in Win10 Terminal too. I will try to set it up this weekend and see if it works for me.Turquoise
Z
6

Unicode bidirectionality (bidi) offers the user the ability to view both right-to-left as well as left-to-right text properly at the same time within the same window. Vim, due to simplicity, does not offer bidi. Instead, it provides commands to make switching between the two directions easier.

" switch to right-left mode (arabic)
:set rl
" switch to left-right mode (english)
:set norl

However, if your terminal supports bidi, you can tell Vim that the terminal is in charge of text direction with the termbidi setting:

set termbidi

If termbidi is set, changing the arabic setting will now only affect your keyboard mapping and the delcombine, which allows you to delete overlapping characters (fathah + letter) individually.

Zen answered 28/2, 2021 at 15:17 Comment(4)
This works good enough for now. Left goes right and right goes left, but I can remap that, or something.Wrapped
@Ibraheem , when I copy and paste, the order of letters is still wrong though. Any idea what to do?Declinate
@Declinate Any updates?Lebbie
No solution found for vim.Declinate
C
0

I use these commands:

:set termbidi
:set arabic

And it works, for me at least.
For more information, use Vim help and read 'arabic.txt', whith this command::help arabic.txt

Cockcrow answered 13/10, 2023 at 23:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.