Write buffer using dos (CRLF) line endings. To convert the current file from any mixture of CRLF/LF-only line endings, so all lines end with CRLF only:
#Mac end of line mac
Or, if it was a mac file to start with, you would use :e ++ff=mac to read the file correctly, so you could convert the line endings to unix or dos. In the above, replacing :set ff=unix with :set ff=mac would write the file with mac (CR-only) line endings.
Write buffer using unix (LF-only) line endings. This buffer will use LF-only line endings when written. To convert the current file from any mixture of CRLF/LF-only line endings, so all lines end with LF only:Įdit file again, using dos file format ( 'fileformats' is ignored). The following procedures will easily handle this situation, but they only work reliably on reasonably recent versions of Vim (7.2.40 or higher). Then you need to change the file format for the buffer and save the file. When reading as dos, all CRLF line endings, and all LF-only line endings, are removed. To fix this, you need to tell Vim to read the file again using dos file format. Entering :set ff? will probably show that the file was read as unix: the problem is that some lines actually end with CRLF while others end with LF. If one or more lines end with LF only, the unix file format will be applied, meaning that each LF is removed (but each CR will be present in the buffer, and will display as ^M), and the buffer 'ff' option will be unix.Ī common problem is that you open a file and see ^M at the end of many lines.If all lines in the file end with CRLF, the dos file format will be applied, meaning that each CRLF is removed when reading the lines into a buffer, and the buffer 'ff' option will be dos.Vim will look for both dos and unix line endings, but Vim has a built-in preference for the unix format.
Suppose your system has ffs=dos,unix and you open an existing file. The order is only important when a new buffer is created (if not empty, the first item in 'ffs' is used as the file format for a new buffer this determines which line endings will be added when the buffer is saved). When a file is read, the order of the items specified in 'ffs' has no effect (for example, ffs=unix,dos has the same effect as ffs=dos,unix when reading). The 'fileformats' option ( 'ffs') has these defaults: However, the above command may indicate that the option was set in your vimrc because that file probably contains set nocompatible which sets many options. The fileformats option is often not explicitly set (the defaults are usually adequate). This command also shows where each option was last set: The following command displays the fileformat option (abbreviated as ff) for the current buffer, and the fileformats global option (abbreviated as ffs) which determines how Vim reads and writes files: :help 'ff' :help 'ffs' :set ff? ffs? The first file format in 'fileformats' is also used as the default for a new buffer. The 'fileformats' option is global and specifies which file formats will be tried when Vim reads a file (unless otherwise specified, Vim attempts to automatically detect which file format should be used to read a file). In addition, the 'fileformat' option can be changed to specify the line endings that will be added to each line when the buffer is written to a file.
#Mac end of line how to
It is set by Vim when a file is read, or can be specified in a command telling Vim how to read a file. The 'fileformat' option is local to each buffer.
#Mac end of line mac os x
Unix based systems and Mac OS X and later.ĬR only (each line ends with a CR character).ĬR is carriage return (return cursor to left margin), which is Ctrl-M or ^M or hex 0D. LF only (each line ends with an LF character). The line terminator expected for each file format is: See below if all you want to know is how to remove ^M characters, or how to fix the line endings in the file you are working on (in brief, enter :e ++ff=dos to remove ^M when viewing a file). Use of the 'fileformat' and 'fileformats' options is also explained. This tip explains how to avoid problems, and how to convert from one file format to another. A file format problem can display ^M characters, or can prevent scripts from running correctly. Vim recognizes three file formats (unix, dos, mac) that determine what line ending characters (line terminators) are removed from each line when a file is read, or are added to each line when a file is written. Tip 1585 Printable Monobook Previous Next