If I open files I created in Windows, the lines all end with ^M
.
How do I delete these characters all at once?
Linux – Convert DOS line endings to Linux line endings in Vim
dos2unixeditorfilelinuxvim
Related Topic
- How to move to end of line in Vim
- Vim clear last search highlighting
- Unix – text files end with a newline
- Your most productive shortcut with Vim
- What’s a quick way to comment/uncomment lines in Vim
- How does the vim “write with sudo” trick work
- How to exit the Vim editor
- Linux – How to find all files containing specific text on Linux
Best 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.There is documentation on the fileformat setting, 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.