Re: set ff=dos problems
Tony Mechelynck <antoine.mechelynck <at> gmail.com>
2008-12-01 02:02:13 GMT
On 01/12/08 01:52, Mike Hoy wrote:
> In my .vimrc file I have:
>
> set ff=dos
>
> and it doesn't format my files for dos. I have to type it out before
> saving it. Any way to automate this? My instructor only uses notepad
> to view code and I'm on GNU/Linux. I'd like to be able to just use vim
> and it automatically saves it in dos format.
>
When Vim open an existing file for editing, it checks the ends-of-files,
and remembers how they were set in order not to change the setting when
writing. This is good and proper, and governed by the 'fileformats'
options. With recent Vim versions (7.2.040 or later) this can be
overridden both when reading and writing. This is what I recommend:
- keep 'fileformats' at its default, or maybe make it universal by
" in the vimrc
set ffs=unix,dos,mac
- to create _new_ files with 'dos' fileformat by default (I'm not sure
this blanketwise use of ff=dos is something that can be recommended on
Linux; if I were you I would try to limit it to ONLY the files which
your instructor will ever see -- see below).
" in the vimrc
setglobal ff=dos
- to _change_ the fileformat of an existing file: after reading and
before saving
" at the keyboard while editing
:setlocal ff=dos
- It is NOT recommended to change every file to "dos" fileformat, even
those which will never be sent to your instructor, because if you do,
you will probably create (not always intentionally) a mixture of
dos-like and Unix-like files on your computer, with the risk of getting
error messages from gcc, patch, make, bash, or other typical "unix"
utilities because they found ^M bytes at the end of almost every line in
some file. Even Vim for Unix/Linux cannot understand vim scripts
(including your vimrc) if they have dos-like ends of lines. (OTOH, with
their default settings, Vim for Windows and Vim for Mac do understand
unix-like scripts.) It is possible but *very dangerous* -- IF I WERE YOU
I WOULDN'T DO IT. Here's how:
" in the vimrc
au BufWritePre * if &ma && !&ro | set ff=dos | endif
The test on (&ma && !&ro) is meant to avoid doing it for 'nomodifiable'
and 'readonly' files but IT IS NOT FOOLPROOF. If you use this
autocommand (which, again, I do *not* recommend) you will have to make
DEAD SURE that you set 'readonly' (and ff=unix) on EVERY Unix file you
edit, before saving it (even saving it implicitly if you use the
'autowrite' and/or 'autowriteall' options). Even so, you will then have
a hard time modifying Unix files for use on your own computer.
Note for your instructor (in the "been there, done that" line):
------------------------
Notepad is a broken editor, it cannot open correctly any files having
the standard ends-of-lines used by default on all Unix/Linux systems.
Use WordPad instead, it is just as easy to use and works much better.
Best regards,
Tony.
--
--
There was a young man from Bel-Aire
Who was screwing his girl on the stair,
But the banister broke
So he doubled his stroke
And finished her off in mid-air.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---