Convert DOS line endings to Linux line endings in Vim
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.
How to make vim :source accept different line endings?
This is discussed at :h :source_crnl
.
On UNIX systems, which includes Mac OS X, there is no automatic CRLF detection, and an actual CR at the end of a line will may raise an error, e.g. in a mapping. From the help:
On other systems, Vim expects ":source"ed files to end in a <NL>. These always work. If you are using a file with <CR><NL> <EOL>s (for example, a file made on MS-DOS), all lines will have a trailing <CR>.
For best compatibility, it is best to have Vim script files always use NL newlines. These will always work everywhere, provided that the first line of the script doesn't for some reason end in a CR and 'fileformats'
is not empty (it isn't empty by default).
In short, consider converting your line endings to LF.
^M at the end of every line in vim
As a command, type
:%s/^M$//
(To get ^M, press ^V ^M, where ^ is CTRL on most keyboards)
How to convert the ^M linebreak to 'normal' linebreak in a file opened in vim?
This is the only thing that worked for me:
:e ++ff=dos
Found it at: http://vim.wikia.com/wiki/File_format
Convert line endings on save
the :%s\:
in your au
doesn't make sense..
If you want to set some option before write, you can just:
autocmd BufWritePre * set name=value
Related Topics
How to Remove Cached Credentials from Git
How to Test If a Variable Is a Number in Bash
How to Change the Root Directory of an Apache Server
Peak Memory Usage of a Linux/Unix Process
How to Set the Working Directory of the Parent Process
Bash Script Process Substitution Syntax Error: "(" Unexpected
Can Awk Patterns Match Multiple Lines
What's the Difference Between "Statically Linked" and "Not a Dynamic Executable" from Linux Ldd
How to Convert Hex to Ascii Characters in the Linux Shell
Defining a Variable With or Without Export
How to Declare 2D Array in Bash
Cannot Connect to the Docker Daemon At Unix:/Var/Run/Docker.Sock. Is the Docker Daemon Running
Expanding a Bash Array Only Gives the First Element