Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have

set fileformat=unix

in my .vimrc, and yet if I create a file in vim (running in Cygwin) it persists in creating DOS-format files, and I have to run them through dos2unix 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.)

share|improve this question
I 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 a CR+LF instead of the Unix LF or even a dos style LF+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 – Matt Aug 3 '12 at 1:52
@Matt: DOS/Windows does use CR+LF, not LF+CR. – echristopherson Aug 3 '12 at 3:17
I 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. – Matt Aug 3 '12 at 4:55
Are you sure that this .vimrc is even read? Try making a deliberate error and see if vim picks up on it. – Michael Kjörling Aug 3 '12 at 12:41
@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). – iconoclast Aug 3 '12 at 13:52
up vote 8 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.