Probably the FileType event occurs to late. Try something like this:
autocmd FileType dosbatch :e! ++enc=cp850
regards,
Christian
The FileType autocommand event is too late for setting the
'fileencoding', because at that point the file has already been read.
For the same reason it isn't useful to set that option by means of a
modeline.
Try (untested)
au BufReadPre,BufNewFile *.bat,*.btm,*.sys setlocal fenc=cp850
Best regards,
Tony.
--
The notion of a "record" is an obsolete remnant of the days of the
80-column card.
-- Dennis M. Ritchie
This won't work if you edit a batch file and then some non-batch file
(*.c, *.htm, *.txt, whatever; even if you look at a Vim helpfile) in the
same Vim session. Since 'fileencodings' is a global-only option, it will
still be "ucs-bom,cp850,latin1" (where the latin1 part will never be
used, since it is after cp850 which is 8-bit and therefore cannot give a
"fail" signal), so Vim will treat that second file (if it has no BOM) as
if it were in cp850 which is probably not what you want.
Maybe
au BufNewFile,BufReadPre *
\ set fencs=ucs-bom,utf-8,latin1
au BufNewFile,BufReadPre
\ *.bat,*.sys,*.cmd,*.prg,*.ch
\ set fencs=ucs-bom,cp850
The autocommands will be run in the order they were defined, so that for
these 5 extensions the second one takes precedence. The first one should
be set to the defaults you want to use for all other files.
Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
214. Your MCI "Circle of Friends" are all Hayes-compatible.
You can also use the value 'Windows-1252' (the official name) which is
known by iconv and so should work both on Unix Vim statically linked
with +iconv and on Windows Vim dynamically linked with +iconv/dyn if
iconv.dll or libiconv.dll can be found.
>
> s:windows_enc doesn't exist by default. Setting it to cp850 means ALL
> files will be detected with this encoding, if they don't have a BOM.
>
>> This works for me:
>>
>> exec 'autocmd BufReadPre *.bat set fileencodings=ucs-bom,cp850,latin1'
>>
>
> As Tony says, this will set ALL files to cp850, unless they have a
> BOM.
>
> The point of my script snippet was:
>
> 1. For most files, use ucs-bom to use a Unicode encoding if the file
> has a BOM, then try windows-1252, but if the system doesn't recognize
> windows-1252, try latin1 (I actually have more autocmds to check for
> characters specific to windows-1252 and use latin1 if not present).
> 2. For *.bat files only, override this to ONLY try the cmd.exe
> encoding
> 3. Restore option (1) after loading dos files, since the option is
> global and the fenc is already set appropriately
>
Best regards,
Tony.
--
Mencken and Nathan's Fifteenth Law of The Average American:
The worst actress in the company is always the manager's wife.