Problem setting 'fileformat'

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem setting 'fileformat'

Gary Johnson-4
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.

Regards,
Gary

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problem setting 'fileformat'

Christian Brabandt
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.

Best,
Christian
--
Auch der reiche Autor stiehlt oft, weil er denkt, er hätt es ebensogut
erfinden können, und der andere denk auch das.
                -- Jean Paul

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

0001-Make-readfile-aware-of-autocommands.patch (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Problem setting 'fileformat'

Gary Johnson-4
On 2017-01-22, Christian Brabandt wrote:

> Yeah, readfile() does not expect autocommands to change those values.
>
> Attached is a patch that fixes it.

Wonderful!  Thank you so much!

Regards,
Gary

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problem setting 'fileformat'

Bram Moolenaar
In reply to this post by Christian Brabandt

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 -- [hidden email] -- 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 [hidden email].
For more options, visit https://groups.google.com/d/optout.