Wednesday, November 28, 2018

Re: Typing Persian (Farsi) in Vim

On Wed, Nov 28, 2018 at 11:19 PM Bahman Eslami <eslami.bahman@gmail.com> wrote:
>
> On Wednesday, November 28, 2018 at 11:04:29 PM UTC+1, Tony Mechelynck wrote:
> > On Wed, Nov 28, 2018 at 10:23 PM Bahman Eslami <eslami.bahman@gmail.com> wrote:
> > > In a case a user doesn't want to have arabic nor faris in the vim, they can build the vim with the 'normal' feature flag but they would miss other features like langmap, but if they want to build it with langmap feature, they need the 'huge' feature flag which also includes the arabic. There is also no flag to disable nor enable arabic while building the vim. So the only way to disable them is to change the source which is how I do it. Now I give you an example what goes wrong with the arabic enabled.
> >
> > > I use the native terminal app in OSX which supports bidi text perfectly even when it comes to selecting text.
> >
> > What is the $TERM setting when you run Console Vim (not gvim) in that
> > terminal? Depending on its value, there are variant ways to tell Vim
> > that the terminal has full-bidi capabilities:
> >
> > * Possibility 1: $TERM is 'mlterm'
> > o Do nothing. Vim knows that mlterm is a full-bidi terminal.
> > * Possibility 2: $TERM is another unambiguously recognisable name,
> > let's say (for the sake of argument) 'system-bidi'.
> > o Add near the top of yout vimrc the following snippet:
> > if &term == 'system-bidi' && has('arabic')
> > set termbidi
> > endif
> > * Possibility 3: $TERM is not unambiguously recognizable, let's say it
> > is 'xterm' which too many fake-xterm terminals use nowadays:
> > o Start Vim (when running in that terminal) as:
> > vim --cmd 'silent! set termbidi'
> > If your shell supports aliases, you can define the following
> > alias (as I would do it for bash, which is an alias-supporting shell)
> > alias vim='/usr/local/bin/vim --cmd "silent! set termbidi"'
> > Replace /usr/local/bin/vim by the path to your Vim executable
> > if it is something else, of course.
>
> Tony,
>
> Thanks for the explanation. When I echo the $TERM in vim I get: xterm-256color. So I used your solution to add 'set termbidi' with the vim build that includes the arabic feature but I still get incorrect Arabic shaping. I also get very abnormal behavior. If I type the following text or even paste it:
>
> نوتشن فارسی
>
> I get the following result in vim, which even in length does not match the input:
>
> ?~F?~Hشت?~F ?~Aارس?~L
>
> I guess it didn't do much for my case.
>
> Thanks,
> Bahman

Weird. My guess is that there is an encoding misunderstanding, but I
could be wrong about that. AFAIK, the +arabic feature works best when
Vim uses UTF-8 'encoding'. Try adding the following (with the
comments, meant to help you understand it even later on) near the top
of your vimrc:

if has('multi_byte')
if &enc !~? '^u'
if &tenc == ""
let &tenc = &enc
endif
set enc=utf-8
endif
scriptencoding utf-8 " see note 1
" set fencs=ucs-bom,utf-8,default,latin1 " see note 2
setg fenc=utf-8
" setg bomb " see note 3
endif
" Notes:
" 1. :scriptencoding utf-8 means that this vimrc is encoded in UTF-8.
" Anything in ASCII is expressed byte-by-byte identically in
" UTF-8 anyway. The difference is only felt when using
" characters not present in Latin1 or characters whose Latin1
" representation is > 0x7F.
" 2. 'fileencodings' (plural) defines the heuristic used when opening
" an existing file. The value (commented-out) here is Vim's
" Unicode default. Other values can be used depending on
" the language(s) used most on this installation. The actual
" value used should start with "ucs-bom,utf-8" in that order,
" and the last comma-separated field (and _only_ the last one)
" should be an 8-bit charset, which will be used as fallback if
" everything else fails.
" 3. :setg bomb sets the default 'bomb' setting to TRUE when
" creating a new Unicode file. It has its pluses and minuses.
" If the other settings above work the way they should,
" we can try uncommenting that line to see if we prefer
" running Vim with or without it.


Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: