Tuesday, December 11, 2018

Convert DOS line endings to Linux line endings in vim



If I open files I created in Windows, the lines all end with ^M.
How do I delete these characters all at once?


Answer



dos2unix is a commandline utility that will do this, or :%s/^M//g will if you use Ctrl-v Ctrl-m to input the ^M, or you can :set ff=unix and vim will do it for you.



Docs on the 'fileformat' setting are here, and the vim wiki has a comprehensive page on line ending conversions.




Alternately, if you move files back and forth a lot, you might not want to convert them, but rather to do :set ff=dos, so vim will know it's a DOS file and use DOS conventions for line endings.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...