Using vim's :source
command on a vimscript file with dos line endings is giving me errors that it can't deal with ^M
characters.
The ^M
characters are part of dos line endings, but not unix line endings. So it is trying to :source
the file using a unix file format.
The thing is, I have :set fileformats=unix,dos
setting on. When opening and editing the file (not :source:
-ing) there are no line ending problems. Vim sees a file with pure dos line endings and as per fileformats
it adjusts itself accordingly.
:help fileformats
only gives the barest clue that on dos systems if you have :set fileformats=unix,dos
, vim performs an ad-hoc detection of which it should use (and as an irrelevant detail, this :source
detection treats mixed line endings differently than than for opening files).
I'm on a modern mac system, how do I get it to :source
a dos line ending file?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With