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've googled all around and found tons of weird solutions to ^M problem, but couldn't find one and simple: how could I just open any file, like in Notepad++ and work on it? I don't want to mess with LF and CR stuff, anyway git will correct it on push. Is there a "stupid" solution for this issue? One little thing, I'm forced to work in the World Evil OS right now, so the solution should work for it.

share|improve this question
4  
How does Notepad++ handle mixed line endings? –  paraxor Jun 18 '13 at 10:46

3 Answers 3

:set binary

or

$ vim -b file

This will leave all line endings as-is, and lines are separated by single <NL> characters. I don't recommend using it, but you've explicitly asked for a "stupid solution".

share|improve this answer

I advise you to fix your line endings.

To convert the file to \n line endings:

:%s/\r$

To convert the file to \r\n line endings (untested):

:%s/[^\r]\n/\r\n/

You can make vim perform one of these operations automatically when you open a file:

autocmd BufRead, * normal :%s/\r$

You could also use the dos2unix and unix2dos utilites.

share|improve this answer

I use vim on cygwin myself - and if the file is labeled correctly as a dos file, it does not show the ^M characters, and I even have the the info line at the bottom set to tell me if it is a dos or unix type file. Some files may have windows line endings, but still show up as unix - if I run dos2unix on those files it is then fixed, and vim correctly labels it and hides ^M the next time I open that file.

share|improve this answer

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.