IMO, replace text line by line, instead of replace whole region. some text editor can customize newline character.
@shaunlebron newline-at-end-of-file is a pain. I think it's preferred, but doesn't count as a line.
At least, it seemed I screwed up more files when I had Avi never write it then I did when I had Avi always write it.
But I'm actually going to move to storing the file contents as a string, so that the trailing newline isn't changed unless the last line is edited, because I just don't want to be responsible for always changing it 🙂