Converting DOS/Windows Line Endings to Linux Line Endings in Vim
When working across multiple operating systems, you might encounter unwanted characters in your text files, especially if you’ve edited them on Windows and then opened them on Linux. Windows uses a combination of carriage return (\r
) and newline (\n
) characters for line endings, while Linux only uses newline (\n
). In Vim, Windows-style line endings appear as ^M
at the end of each line, which can be distracting and problematic in Linux-based environments.
If you want to convert these Windows line endings to Linux line endings within Vim, here are some methods to do so.
1. Quick Fix Using a Simple Substitution Command
You can quickly remove the ^M
characters (which represent the carriage return, \r
) by running the following substitution command:
Labels: Converting DOS/Windows Line Endings to Linux Line Endings in Vim