Monday, January 23, 2017

Re: Problem setting 'fileformat'

Christian Brabandt wrote:

> Hi Gary!
>
> On So, 22 Jan 2017, Gary Johnson wrote:
>
> > Some of the log files I collect contain both CR and CR-LF line
> > endings. Normally on a Linux system, Vim opens those files as
> > 'fileformat' "unix", which puts ^M at the end of lines ending with
> > CR-LF. I would like to hide those ^M by forcing 'fileformat' to
> > "dos" for those files. I think the following should work, but it
> > doesn't.
> >
> > au BufReadPre mary* set ffs=dos ff=dos
> >
> > (I'm using a test file named mary.txt which contains a mixture of CR
> > and CR-LF line endings.)
> >
> > Instead, whether I start vim with the file name on the command line,
> > e.g., "vim mary.txt", or start vim with no argument and open the
> > file later with ":e mary.txt", the results are the same:
> > 'fileformat' is "unix" and ^M appear at the end of the CR-LF lines.
> >
> > It can be seen from this command,
> >
> > :verbose set ffs? ff?
> > fileformats=dos
> > Last set from ~/.vimrc
> > fileformat=unix
> >
> > that the autocommand is being triggered, but that Vim is setting
> > 'fileformat' to "unix" internally. If Vim is setting 'fileformat'
> > _before_ the autocommand is triggered, it is ignoring the 'ff' in
> > the autocommand. If Vim is setting 'fileformat' _after_ the
> > autocommand is triggered, it is ignoring the 'ffs' in the
> > autocommand. Is this a bug or my lack of understanding?
> >
> > I'm running version 8.0.187 on Linux. I used a ~/.vimrc containing
> > only that autocommand and I moved aside my ~/.vim directory. I even
> > ran vim as "vim -N --noplugin", all with the same results.
>
> Yeah, readfile() does not expect autocommands to change those values.
>
> Attached is a patch that fixes it.

Thanks!

--
A vacation is a period of travel during which you find that you
took twice as many clothes and half as much money as you needed.

/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
--
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: