You are not logged in.
I'm editing an XML file in geany in Windows.
geany says this file is UTF-8 with CR/LF line endings, so I have this modeline in the file:
<!-- vim: set ts=4 ff=dos : -->
When I open the file for editing in Vim I have confirmed the filetype is dos with :set ff? and the encoding is utf8 with :set enc?
However, if I :q it prompts to save changes even if I don't change anything. If I give in and :wq then svn diff shows the whole file has changed.
However, if I save a new version of the file from Vim, rather than overwriting and compare the with normal diff it finds no changes at all.
This is annoying because if I make a single change in Linux then SVN commits show a total file change, which is obviously useless.
Vim seems to be changing something which diff ignores and svn diff detects - but I dunno what.
Suggestions, please!
Offline
OK, cat does indeed show that my original file doesn't have the ^M carriage returns but after a save in Vim it does.
What seems paradoxical to me is that geany is set to CR/LF line endings already, so why do they only "appear" after a save in Vim, should geany not put them in too?
I don't get it.
Offline
I've resolved the problem by using:
<!-- vim: set ts=4 ff=unix : -->
geany is still set to CR/LF but it doesn't appear to be saving any CR...
So, I just guess just go with what works?!
Offline
Good reason to use a real editor.
You're right, that does sound odd. Was the file created in Geany, or just opened that way?
... wait, here's what's going on. Geany opened a file with Unix line endings. It displayed correctly because Geany isn't stupid like Notepad, but Geany didn't convert the line endings when you closed the file because you didn't tell it to. But Vim modelines take effect as if you had typed them in after opening the file. So Vim detected that the file had Unix line endings, and opened it with fileformat=unix. Then the modeline set fileformat=dos. When you hit :w, Vim saved it with DOS line endings.
The moral of the story? Don't use modelines, and if you do, don't use them to set the file format. (Vim detects that automatically.)
Offline