On Fri, 23 Jul 2010, Nikolai Weibull wrote:

> Bram Moolenaar wrote:
> 
> > Patrick Texier wrote:
> 
> >> No, it is the right way to define encoding of a 8-bit file. Vim can not
> >> choose between ISO-8859-1(15), cp1252, cp1250...
> 
> > I'm trying to think of a valid reason to change
> > 'fenc' in the modeline.  Can't think of one...
> 
> Oh, wait, the order is wrong, here, let me fix it:
> 
> Patrick Texier wrote:
> 
> > Bram Moolenaar wrote:
> 
> >> I'm trying to think of a valid reason to change
> >> 'fenc' in the modeline.  Can't think of one...
> 
> > No, it is the right way to define encoding of a 8-bit file. Vim can not
> > choose between ISO-8859-1(15), cp1252, cp1250...
> 
> There, that makes a lot more sense.
> 

As Bram asserted, modelines take effect too late to serve this purpose.  
The file has already been read by the time the 'set fenc=whatever' takes 
place.  The only way to do this right is to tell Vim to expect the 
encoding you're going to need.  One of:

set fenc when opening Vim: vim +'set fenc=cp1252' filename

or tell Vim to always expect CP1252, in RC files: set fencs=utf-8,cp1252

or while opening within Vim: :e ++enc=cp1252 filename


If you want to get fancy, an autocmd to parse some type of metadata in 
the file *might* help (but again, I'm not sure of the execution order).

Completely untested:

fun! SetCP1252(file)
    let found=system('head -n 100 '.shellescape(a:file).' | grep -i "cp-?1252"')
    if strlen(found)
        setl fenc=cp1252
    endif
endfun
aug HackyDetect
    au BufReadPre *.html :call SetCP1252('<amatch>')
aug END

-- 
You received this message from the "vim_dev" 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

Raspunde prin e-mail lui