Unix & Linux
vim windows cygwin
Updated Fri, 20 May 2022 17:16:24 GMT

Why is vim creating files with DOS line endings?


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.)




Solution

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.