On 1/18/07, DervishD <[EMAIL PROTECTED]> wrote:
    Hi Bram :)

 * Bram Moolenaar <[EMAIL PROTECTED]> dixit:
> DervishD wrote:
> >     I've done the following autocommand to perform the detection:
> >
> > autocmd BufReadPre *
> >     \ if system("file -i " . expand("<amatch>")) =~ "utf8" |
> >     \   setlocal fenc=utf8 |
> >     \ endif
> >
> >     I'm sure that it could be much more simpler and powerful, but I'm a
> > newbie programming in VimL, so... It works for me, at least, but any
> > suggestion is welcome.
>
> Did you set 'fileencodings' to an empty string?  Otherwise this would
> not work.

    Apart from fixing the above (including the last version I posted
here, which has a catch, yes, I have "fileencodings" set to an empty
string. Why this wouldn't work if 'fencs' is not an empty string? Is
because 'fenc' will get a value *after* the autocommand is invoked?.

'Fileencodings' is the option to detect the file encoding, and
'fileencoding' is the option to set/reflect the encoding of the
current file.

In my _vimrc, I have settings like:

 function! SetFileEncodings(encodings)
   let b:my_fileencodings_bak=&fileencodings
   let &fileencodings=a:encodings
 endfunction

 function! RestoreFileEncodings()
   let &fileencodings=b:my_fileencodings_bak
   unlet b:my_fileencodings_bak
 endfunction

 au BufReadPre  *.gb               call SetFileEncodings('cp936')
 au BufReadPre  *.big5             call SetFileEncodings('cp950')
 au BufReadPre  *.nfo              call SetFileEncodings('cp437')
 au BufReadPost *.gb,*.big5,*.nfo  call RestoreFileEncodings()

You may use a similar way.

Best regards,

Yongwei
--
Wu Yongwei
URL: http://wyw.dcweb.cn/

Reply via email to