How to make vim: source accepts different line endings?

Using the vim :source command in a vimscript file with dos line outputs gives me errors that cannot deal with ^M characters.

The ^M characters are part of the dos line endings, but not UNIX line endings. Therefore, the :source file :source trying to use a unix file.

The fact is that I am setting :set fileformats=unix,dos . When opening and editing a file (not :source: -ing), there are no problems with line endings. Vim sees the file with the end of the final board, and according to fileformats it is configured itself.

:help fileformats gives only the most common key that on dos systems, if you have :set fileformats=unix,dos , vim performs a special discovery that it should use (and as an irrelevant detail this detection :source refers to the ends of the mixed line otherwise than when opening files).

I am on a modern Mac system, how can I get it to :source dos line ending file?

+6
source share
1 answer

This is discussed in :h :source_crnl .

On UNIX systems, including Mac OS X, there is no automatic CRLF detection, and the actual CR at the end of the line will cause an error, for example. in display. Via:

On other systems, Vim expects ": source" ed files to be completed in <NL>. They always work. If you use a file with <CR> <NL> <EOL> s (for example, a file made in MS-DOS), all lines will have a trailing <CR>.

For better compatibility, it is best that Vim script files always use NL strings. They will always work everywhere, provided that the first line of the script for some reason does not end in CR, and 'fileformats' not empty (by default it is not empty).

In short, consider converting line endings to LF.

+6
source

All Articles