How to convert to/from DOS format in VIM…

It’s very easy, but also easy to forget how to convert to or from a DOS format file in Unix using “vim” (Vi iMproved), the Open Source “vi”. If the file is in DOS format and you want to convert to Unix, use the command:

:set ff=unix

note that “ff” is an abreviation for “fileformat” which you can also use.

If the file is Unix and you want to write DOS format, use the following command:

:set ff=dos

In both examples it is assuming you are ESCaped out of edit mode and the leading “:” is required.

Note that the difference between the two formats is that:

  • DOS format ends each line with a CRLF (carriage-return line-feed) pair.
  • Unix format ends each line with a simple LF (line feed).

Neither of these forms should be confused with the C language string delimiter ‘NUL’ which is an ASCII “zero”. That however is an entirely different subject.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">