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.
--
Mike Hoy
Hi Mike.
The problem is that it's set explicitely when opening a file per buffer.
And per buffer settings override the default one.
However I strongly discourage this way to do it *for all* files.
Because you'll happen to edit you ~/.bashrc file as well and then: oh
dear, bash won't read it :-)
The way to go is using autocommands after creating, reading or before
writing them.
But I'd either use a localvimrc http://www.vim.org/scripts/script.php?script_id=441
to setup this autocommand or use a confirmation to remember you that you
should use dos format for files.
For example something like this should do it (untested):
autocmd BufWritePre * if &ff != 'dos' && input('set ff to dos [y]') == 'y' | setlocal ff=dos | endif
Then you'll continue to edit other files with vim as well..
Enjoy
Marc Weber
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.
The following tip is a bit of a mess, but there is some useful info that might
assist:
http://vim.wikia.com/wiki/Change_end-of-line_format_for_dos-mac-unix
I think the problem is that Vim tries to retain the fileformat (line ending) that it
finds when reading the file. The command 'set ff=dos' is talking about the current
buffer, not files that you open in the future.
An autocmd that sets ff for all files in a certain directory might suit, or you
could have a script that you run to prepare files before sending.
John
Mike,
If you need it, there is a script to convert between dos/unix/mac EOLs
here: www.noels-lab.com/crlf.html.
I know it's not the same, but it might help.
Noel
--
------------------------------------------------------------------
Noel Henson
www.noels-lab.com Chips, firmware and embedded systems
www.vimoutliner.org Work fast. Think well.
It does not work for me. :set ff=unix in _vimrc works for me, but
only before I open a new a DOS file. It seems nothing works stably
for new file (on Windows) to achieve your purpose.
--
Wu Yongwei
URL: http://wyw.dcweb.cn/
Exactly as it literally means. When I have :set ffs=unix,dos in
_vimrc, the empty file on opening vim, or results of :enew, still has
ff=dos on Windows.
I even tried putting set ffs=unix,dos in a test.vim, and started vim
with gvim -u test.vim --noplugin, and the result was still the same:
ff=dos. Putting in set ff=unix has effects.
I really can't imagine why it works for you.
I am using gvim 7.2.60 on Windows XP.
Best regards,
Yongwei
Path to my test.vim.
> I don't think it should matter, but:
>
> "Using the '-u' argument has the side effect that the 'compatible'
> option will be on by default." (:help -u)
Adding :set nocompatible in test.vim makes no difference.
> Maybe you are setting 'nocompatible' somewhere after you set the ffs
> value, resetting it to the default?
And it does not matter, since I checked the value of ffs in vim.
>> I really can't imagine why it works for you.
>>
> And I can't imagine why it doesn't for you :-)
Strictly speaking, my results make more sense. Vim help file does not
say that the first value in ffs will be used as the default encoding.
On the contrary, I know that setting the value of fenc will affect the
encoding of the empty file. And it does not persist, since neither
fenc nor ff is really 'global': Vim help states clearly that they are
local to buffer.
>> I am using gvim 7.2.60 on Windows XP.
>>
>
> Me, too. The 'cream' compile from sourceforge.
I use my own build (executables only), available at:
http://wyw.dcweb.cn/download.asp?path=vim&file=gvim72.zip
You may have a try, but I do not think it can make a difference. I
would rather think your environment affected. Did you try with -u
test.vim, as I did?
If you want to start Vim with standard startup scripts, it is also possible:
cd "C:\Program Files\vim\vim72"
.\gvim -u vimrc_example.vim
starts with a standard vimrc which sets 'nocompatible'. It also loads
all global plugins.
gvim -u NORC -N
starts gvim with plugins but no vimrc, in 'nocompatible' mode.
gvim -u NONE -N
starts gvim in 'nocompatible' mode with no vimrc and no plugins.
gvim -u test.vim --noplugin
starts with no plugins and test.vim as the only vimrc. 'compatible' will
be on unless and until test.vim sets 'nocompatible'.
And so on.
I'm using an own-compiled gvim 7.2.64 with GTK2 GUI on openSUSE Linux,
so I don't think my results are easily comparable with yours what
concerns platform-dependent options like 'ff' and 'ffs'.
Best regards,
Tony.
--
It's the thought, if any, that counts!
All buffer-local option have a global counterpart. ":set option=value"
sets both. ":setlocal option=value" sets only the current local value.
":setglobal option=value" sets only the global default. OTOH, ":set
option?" displays the current local value if any; you need ":setglobal
option?" to display the global value. In the latter two cases, prefixing
with ":verbose " tells you where the value in question was set.
See ":help local-options".
Normally, the global setting is used when creating a file which doesn't
yet exist. However, in the case of 'fenc' 'ff' and 'binary', the ++enc,
++ff, ++bin and ++nobin arguments to ":edit" (and some other commands)
can override this.
See ":help ++opt".
Best regards,
Tony.
--
"I'd love to go out with you, but I'm doing door-to-door collecting for
static cling."
Our results are aligned then. I only check the ff of the empty file on
opening vim and the result of :enew. Neither is affected by ffs. When
I try :new and :tabnew now, you results can be reproduced.
However, since :enew and the default empty file does not work as you
expected, your method is not reliable. Probably you want to file a bug
report to Bram.
In the meantime (until Bram changes, if ever, the behaviour of ":enew"
to make it match the help), you may define a new command, let's say
command -bang -bar -nargs=0 Enew enew<bang> | set ff=dos
Best regards,
Tony.
--
Different all twisty a of in maze are you, passages little.