Take the 2-minute tour ×
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.

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 files, and I have to run the little cotton-pickers 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

1 Answer 1

up vote 4 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
    
I added that, and (very strangely) got ".vimrc" [unix] 128L, 4601C Error detected while processing C:\Applications\Git\share\vim\vim73\scripts.vim: line 1: W15: Warning: Wrong line separator, ^M may be missing Press ENTER or type command to continue. It's as if something somewhere is set to tell vim to expect the wrong line terminator. –  iconoclast Aug 3 '12 at 13:54
2  
I was able to reproduce your problem and I think I found the fix. I updated my answer, please try it! –  janos Aug 8 '12 at 15:12
    
Brilliant! Thanks! –  iconoclast Aug 8 '12 at 19:47

Your Answer

 
discard

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.