A shell script that came from Windows fails with odd errors like bad interpreter and a ^M. The line endings are the problem, and Vim fixes them in one line.
:set ff?
:set ff=unix
:w
ff is short for fileformat. The first command shows what Vim detected: dos means every line ends in a carriage return and a newline. Setting it to unix and saving writes the file with plain newlines. The text itself doesn’t change.
Vim hides the carriage returns when it detects a DOS file, so the file looks normal until you check this option.
Files with mixed line endings are a different story. Vim reads those as unix and shows ^M at the end of some lines. A substitute removes them:
:%s/\r$//
The other direction works too: :set ff=dos before saving gives a file that old Windows tools like.
For a batch of files I’d use dos2unix or sed in the shell instead. And if the file is in Git, check core.autocrlf, since Git may convert the endings back on the next checkout.
Further reading: Vim help: 'fileformat', Vim help: file formats
Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more