Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 669
Eugene Yarmash Avatar asked Feb 03 '10 00:02

Eugene Yarmash


2 Answers

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

like image 60
Merlyn Morgan-Graham Avatar answered Oct 23 '22 14:10

Merlyn Morgan-Graham


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
like image 43
Jackson Miller Avatar answered Oct 23 '22 13:10

Jackson Miller