Why is vim creating files with DOS line endings?
Setting only fileformat
may not be enough, depending on a few factors. Try this:
set fileformat=unix
set fileformats=unix,dos
"set nobinary
To understand what these do, have a look at :help fileformats
, etc.
I think I am able to reproduce your issues, using the vim.exe
provided by git
in windows. Using the above settings fixed the problem for me. In the example set nobinary
is commented out because I don't think you need it, I left it there as a tip that might help in case you need to investigate further.
Related videos on Youtube
iconoclast
Contractor at Infinite Red, a mobile app & web site design & development company with employees worldwide, experts in React Native, Rails, Phoenix, and all things JavaScript!
Updated on September 18, 2022Comments
-
iconoclast over 1 year
I have
set fileformat=unix
in my
.vimrc
, and yet if I create a file invim
(running in Cygwin) it persists in creating DOS-format files, and I have to run them throughdos2unix
to clean them. (I guess I don't really have to, since Git cleans them up for me, but it just bugs me to death that a Unix text editor, which I've specifically instructed to use Unix line endings, is polluting them with extra garbage.)Why would this happen? How can I fix it? (And by "fix" I do not mean something that requires me to convert each file individually. That's not a fix. That's what's totally broken.)
-
Matt almost 12 yearsI would wager this is a cygwin problem. There is an option in cygwin to choose the line ending style but I hven't seen any evidence it actually works. My university uses Eclipse with cygwin for the GNU compiler collection and I encountered a weird behavior with
getline
which turned out to be cygwin doing something weird. Resulted in aCR+LF
instead of the UnixLF
or even a dos styleLF+CR
. You should check and see what line ending style you have configured in cygwin but YMMV. See also cygwin.com/faq/faq-nochunks.html#faq.api.cr-lf -
echristopherson almost 12 years@Matt: DOS/Windows does use
CR+LF
, notLF+CR
. -
Matt almost 12 yearsI was afraid I'd swap those if I didn't double check, been over a semester since I had that issue. The line endings were different when running in cygwin and when running at the dos prompt and I remember being convinced it was backwards from what you'd expect from DOS but as you can see they're easy for me to switch up.
-
user almost 12 yearsAre you sure that this .vimrc is even read? Try making a deliberate error and see if vim picks up on it.
-
iconoclast almost 12 years@MichaelKjörling: yeah, I tested, and it is being read. I commented out my
set number
line, and it took effect, and uncommented it out and that took effect. I also added "blah blah blah" at the bottom, and got "Press ENTER or type command to continue" when I opened anything, but oddly there was no error message before that (unless it was black letters on black background).
-