Why is [dos] sometimes in the output of a save in “vim”. such as: “foo.txt [dos] 38L, 193C”

command linefilevi

In certain text files, after doing a save in vim with :w, the output mentions [dos] as such:
"foo.txt" [dos] 38L, 193C

Why is [dos] displayed?

As a simple test, I've created a new file with vim on a FAT32 disk attached to my Mac. Those files don't display [dos] after a save in vim. I copied that file to /tmp (native MacOS format). Opening it there does not display [dos] upon a save in vim either.

So, foo.txt has Japanese characters. A portion looks like:








"foo.txt" [dos] 38L, 193C

some testing:

/tmp$ file -I foo.txt
foo.txt: text/plain; charset=utf-8

foo.txt life cycle:

  1. On XP I created lots of text files using TextEdit that had Japanese characters and saved to FAT32 file system (usb drive).
  2. They were archived into a ZIP format.
  3. That usb drive was attached and copied to my MacBook (MacOS Extended / Journaled).
  4. /usr/bin/unzip unarchived them, and here I am.

Text files are such a basic cross-platform file format. Obviously, "something" is different with those [dos] marked files… What flags a file as being a [dos] file?

Best Answer

What flags a file as being a [dos] file?

Line endings. Windows uses CR (carrage return) and NL (newline) characters. Old Mac plain text files use CR and macOS command line editors use NL.