I think you might be misunderstanding how the
'fileformats' (plural) setting is used. This setting is a global list of file formats that Vim tries when opening any file in order to see which matches the format of the file. When it has detected the format, Vim sets the per-file
'fileformat' (singular) option for that individual file.
If you are setting
'fileformats' to e.g.
dos in a modeline, you are instructing Vim to consider all files to have dos line endings, regardless of the actual content of the file, so when you subsequently open a file with
unix endings, Vim is still forced to treat it as a
Note that this only affects files that you open later on, as when you opened the first file
'fileformats' was set to the default value of
dos,unix): Vim is correctly detecting the format of the first file, and then reading the modeline which changes the value used for detection from that point on.
Note also that when you open the second file, its modeline is being executed (which you can see if you run the command
:verbose set ffs?), but, like before, the updated
'fileformats' doesn’t take effect until the next time you read a file, which you are doing by manually invoking
If you remove all the
ffs settings from your modelines, Vim will use the default
'fileformats' value of
dos,unix) and correctly set the per-file
'fileformat' based on the content of the file.
If, however, you are dead set on hard-coding your file formats into your modelines, you should at the very least change your
ffs modelines into
ff modelines. In this way, Vim will still detect the file format based on the content of the file on opening, but will then immediately override the file format (changing the line endings if necessary and marking the file as modified), so if you somehow accidentally change the
'fileformat' before writing (which you mention doing in a comment), this will be corrected the next time you open the file in Vim.