tags:

views:

126

answers:

4

Vim won't convert fileformat if it sees inconsistent line endings. How can I find those ?

+3  A: 

How about replacing \r\n with \n and then \n with \r\n.

Should be something like:

  :%s/\r\n/\n
  :%s/\n/\r\n
Jackson Miller
+2  A: 

To change all line endings that are \r\n to \n, use

:%s/\r$//

This will search for all \r characters followed by newline and replace it with just newline

Andres
+2  A: 

Use a utility like dos2unix or unix2dos to convert the line endings to the desired format. There are native implementations of these utilities for both unix and windows systems.

calid
+4  A: 

Zero-width look-behind assertion

"How do I search for “\n” without a preceding “\r” in vim ?"

/\r\@<!\n

How do you search and replace these occurances with "\r\n"?

:%s/\r\@<!\n/\r\n/gc

Get rid of the final "c" if you want to accept every match without confirmation.

Edit: However, if you want an answer that you can remember how to do without having used look ahead/behind assertions a billion times, see Jackson Miller's answer. Sometimes it is better to simplify your problem and use tools that don't require you to read the manual constantly :)

Merlyn Morgan-Graham
The search did the trick for me.BTW, line endings can be changed with :e ++ff=dos, then :w
eugene y
wow i did not know vim supported look-behind, cool!
calid
Hey, I like your way better Merlyn. I just tend to get it done with what I know how to do.
Jackson Miller