Feb
12
2010

Vi And No End Of Line

Friday, February 12, 2010 - 01:51:34 pm
(Posted Under: Development)
This is a constant problem. Editing files in vim that don't have an end of line character at the end of the file results in an end of line character being added when saving.

It's probably fine to terminate every file with an end of line, though it annoys me when I do a cvs diff on code and get more line changes that are actually warranted with a given bug fix or code update. It generally happens from creating a file in a Windows editor (namely Textpad) without a final end of line and then doing some work in vim and saving. Typically I'll open the file back up in Textpad, remove the end of line and resave before comitting the code, but that can be a pain when I specifically want to keep working in vim, or if I don't have a Windows editor handy (or feel like navigating through a whole bunch of folders to open the file in Windows).

I have pretty much found the solution to the problem.

Under Windows/cygwin it's relatively easy - remove the end of line, "set binary noeol" in vim and save the file. That does the trick.

Under Linux, it's a can bit more of a pain.

  • "set binary noeol" works fine on Unix (\n only) files
  • On Windows (\r\n) files, the binary option removes all \r's, which will cause far more havock on a cvs diff [smile] However, it seems that doing a unix2dos on the saved files will return the file to \r\n) line endings, without causing the final end of line to be re-added.
With that said, I should just add eol's to files to avoid any hassles, but since I'm more likely to only do that on a separate development/cleanup branch, the above trick is handy for day to day workings with files.

Post Comment



All fields are required. Email addresses will not be published, but are required for anti-spam purposas.

Switch Styles

About Style Switching.

!Weblog Index

Jan February 2010 Mar
SU MO TU WE TH FR SA
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28

Categories

RSS FeedRSS Feed