Strange But Universal(?) Editor Feature

Note: This entry has been restored from old archives.

I was wondering why some of my results were going wrong when doing some pattern matching in Perl. I have a file that gets generated by a script and has one big RE on a line that is read into another script and executed. For some reason the RE doesn’t match what it should… just then I accidentally discovered that it does match and then doesn’t match if I have had the file open in vim, so even though all I am doing is opening the file and then immediately doing a :wq (should just be a :q then I wouldn’t have had this problem, but I do also need to tweak the RE a bit at times) the file content is modified!

What is weird is I then tried the same thing in nvi and then in pico and they do the same thing! At this point I’m checking the difference using md5sum. Each editor spits out the same slightly modified file?!?!

What’s the difference? The file ends up one byte longer… all three editors add a ‘n’ to the end of the file without being asked to.

At first I thought it was something to do with line length (my RE is over 400,000 chars long) but the editors do this for files with a single line only three chars long too… so why do they do this? If three out of three editors tested do the same thing it indicates that it might not be a random decision. As far as I know the editors have completely different codebases, so it isn’t just a shared bit of buggy (unless something in a shared library is doing it). I have a suspicion that there is a reason for this and I wonder what it is!

For now I’ll just add the chomp to my Perl script (it should have been there in the first place) and seek enlightenment later.