Reply to message «enc,fenc (again!?)», 
sent 20:57:23 24 October 2010, Sunday
by Alessandro Antonello:

> Some times I need to work with several buffer. Some in natural 'utf-8'
> encoding. I say natural because it is the system default (I am in a Mac)
> and is defined in Vim 'encoding' option. But some buffer I need to be in
> 'latin1'. Opening the files in the right encoding is easy, since I use the
> '++enc' option. So the files are read correctly. The problem begins when I
> use 'bnext' and 'bprevious' (or another similar command) to navigate
> between the buffers. Since my encoding is 'utf-8', when I navigate from a
> buffer with this encoding to a buffer that was opened with '++enc=latin1'
> this buffer get its encoding changed to 'utf-8'.
You should have written a script that shows your problem and uses `-u NONE'. I 
managed to reproduce this behavior with the following script:
    touch a
    touch b
    vim -u NONE -c 'set nohidden' \
                -c 'e a' \
                -c 'echo &fenc' \
                -c 'e ++enc=latin1 b' \
                -c 'echo &fenc' \
                -c 'bn' \
                -c 'bn' \
                -c 'echo &fenc' \
                -c 'qa!'
Output:
    "a" строк: 0, символов: 0
    utf-8
    "b" [перекодировано] строк: 0, символов: 0
    latin1
    "a" строк: 0, символов: 0
    "b" строк: 0, символов: 0
    utf-8
vim-7.3 from Gentoo repos. I do not know, whether this is intended behavior 
when 
buffer is abandoned, but this does not happen if you add `set hidden' somewhere 
into .vimrc.

Original message:
> Hi, all.
> 
> I know that this has been discussed for a long time but I still don't
> understand why Vim behaves like that.
> 
> Some times I need to work with several buffer. Some in natural 'utf-8'
> encoding. I say natural because it is the system default (I am in a Mac)
> and is defined in Vim 'encoding' option. But some buffer I need to be in
> 'latin1'. Opening the files in the right encoding is easy, since I use the
> '++enc' option. So the files are read correctly. The problem begins when I
> use 'bnext' and 'bprevious' (or another similar command) to navigate
> between the buffers. Since my encoding is 'utf-8', when I navigate from a
> buffer with this encoding to a buffer that was opened with '++enc=latin1'
> this buffer get its encoding changed to 'utf-8'.
> 
> I am trying to solve this problem for a long time and never accomplished
> it. What I can't understand is why Vim ignores the buffer 'fileencoding'
> variable? It is set correctly and is set when the buffer is opened. To be
> sure about that I manually set the 'fileencoding' variable when the buffer
> is opened.
> 
> Let me explain this right. I open a file with '++enc=latin1'. In the
> 'BufRead' auto command I set the 'fenc' variable as this: call
> setbufvar('%', '&fenc', 'latin1').
> 
> Then I navigate to another buffer that is in another encoding (like
> 'utf-8'). When I come back to the first buffer, its 'fenc' variable is
> 'utf-8' and I don't understand why!
> 
> My current global configuration is as follows:
> 
> encoding=utf-8
> fileencodings=ucs-bom,utf-8,default,latin1
> fileencoding=utf-8

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to