Question

I use Vim and GIT to develop my project on a Linux/Ubuntu machine. In the past, I used to use Windows, which means line ends were DOS format. Now after moving to Linux, I always see ^M confusing/annoying characters at the end of the line. Some people here:

How to convert the ^M linebreak to 'normal' linebreak in a file opened in vim?

suggested that I should make a find/replace or use tools like dos2unix. These are good suggestions, but with a version-controlled project it means I have to add unnecessary commits for the files after change, and it is a big task anyway that is not worth spending time on it. So:

Is there anyway to make Vim tolerant for this? That is, if the file is DOS line-ended, it keeps it like this, and use its formatting for new newlines, and so on.

Was it helpful?

Solution 3

The best answer I found is @Keith answer in the comments:

"With subversion you can set a property svn:eol-style=native that will cause it to convert line endings to.. native type for all platforms automatically. I don't know if git has that feature, but you might look into that first. It probably does."

And these links might be useful link is how to set:
http://help.github.com/dealing-with-lineendings/
http://git-scm.com/docs/gitattributes

OTHER TIPS

I have added this line to my .vimrc file.

set fileformats=unix,mac,dos                

If you don't know what a vimrc file is, it's simply the file that configure (and allows you to customize) your vim. By default vim will be looking for a file called .vimrc (notice the dot at the beginning) in the user's home folder. If it cannot find it, it will source it from /etc/vimrc.

Yes, you can set the following in vim to say it's a dos format file:

:set ff=dos

And, likewise:

:set ff=unix
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top