Bidi support in Vim, should I revert to Notepad++?

5

1

Good day everyone,

Seven weeks ago, I started learning Vim. I tried it in the past a lot, but this time wasn't like every instance in the past. I got it, and Vim became a habit that I can't quit. I even wrote my vimrc and I can't believe that I lived in an era where I used to use glorified notepad(s). I am by no means an expert or an intermediate level Vimmer. I am just a noob who wants to continue using Vim in his daily programming life. This sounds more romantic than pragmatic but it is the truth.

This week, I needed to edit files that contain languages other than English. It is Arabic, but the problem applies also to Hebrew and Farsi(Persian). It was a shock to me, that Vim doesn't support bidirectional text. The (not so good) solution is to have two tabs one left to right and the other right to left, but that is quit ugly in my opinion. The only editor on my machine that doesn't support bidi text is edit(The command line editor in Windows!).

Is there a solution, or should I revert back to Notepad++ and forget about Vim?

I find it hard to keep switching between Notepad++ and Vim because I edit lots of files that contain bidi text.

Thanks everyone,

AraK

Posted 2012-07-30T00:11:57.990

Reputation: 151

2Does :set rl not work for you? – Paul – 2012-07-30T01:37:38.227

Answers

7

Vim doesn't support bi-directional text. IIRC this subject has been discussed a lot on the vim mailing lists with no advance whatsoever.

See :help hebrew and :help rileft, in which you can find this paragraph:

Bidirectionality (or bidi for short) is what Unicode offers as a full solution to these languages. 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 currently, due to simplicity, does not offer bidi and is merely opting to present a functional means to display/enter/use right-to-left languages.

So I see 3 options for you:

  • go back to Notepad++
  • use the workarounds found in :help hebrew, including :set rl and :set revins
  • keep juggling between the two editors

romainl

Posted 2012-07-30T00:11:57.990

Reputation: 19 227

1

You do not need to revert to Notepad++ See here:

In debian, do as root or sudo: (sudo) apt install mlterm

man mlterm see the manual page for mlterm mlterm -b grey -w 18 starts mlterm with grey background and font size 18

Open vim (not gvim) in mlterm to see Hebrew written correctly - from right to left. In emacs it is an automatic setup - you can test it copying any vocabulary from the Step Bible site in a file and open it like so in mlterm: vim file.md

How to write Hebrew and Arabic in vim? In vim, use these commands: :set rl :set revins : set norl :set norevins :set spelllang=en,he - unfortunately these commands write everything from right to left, including European languages. So that, the solution is to open vim (not gvim) in mlterm and all things will be good to go :)

In emacs - using evil-mode (that's the mode I use most) it's bidi (Hebrew and Arabic et.al.) RL languages are setup in the right way when mixed with LR - European languages :)

Do not forget to add an Hebrew/Arabic keyboard in your Debian (or other distro) setup and a shortcut to change them accordingly.

Achylles

Posted 2012-07-30T00:11:57.990

Reputation: 11

1

I also have the same problem. Ultimately the solution is to use another editor. So you can keep both editors open and both of them should be capable of auto updating when the file gets changed. Gvim is like that if set autoread is in your .vimrc file.

rowman

Posted 2012-07-30T00:11:57.990

Reputation: 335

1

As the others answered before, Vim doesn't have BiDi support.
You can, however, get most of that functionality from emacs with evil-mode installed. Emacs supports BiDi out of the box, and evil-mode contains all of the common vim keybindings (or at least all of those I found myself using. Your mileage may vary). Just be sure to not type hebrew directly from your OS, but instead have your system set to English and change input methods inside emacs to hebrew. That is accomplished with the

M-x set-input-method

command and answering hebrew when prompted, or by adding the line

'(default-input-method "hebrew")

under custom-set-variables in your ~/.emacs file.
After either addition, you can use C-\ to switch between English and Hebrew without losing your vim-like functionality when typing in Hebrew.

I answered for Hebrew since that was the fix I needed. Obviously this all works for Arabic as well.

Nuclearo

Posted 2012-07-30T00:11:57.990

Reputation: 11