editing a file with vim that has no EOL marker on the last line but has CRLF line endings

Posted by rmeador on Stack Overflow See other posts from Stack Overflow or by rmeador
Published on 2010-04-20T21:14:13Z Indexed on 2010/04/21 2:23 UTC
Read the original article Hit count: 338

Filed under:
|
|
|

I often have to edit script files, the interpreter for which treats files that have an EOL marker on the last line of the file as an error (i.e. the file is treating CRLF as "newlines", not as "line endings"). Currently, I open these files in Vim using binary mode (-b on the command line). It autodetects the lack of EOL on the final line and sets the "noeol" option appropriately, which prevents it from writing an EOL on the last line. Because the file has CRLF line endings, I get lots of ^Ms at the end of my lines (because it interprets only Unix-style line endings in binary mode, it seems). I can't open it in text mode because the "noeol" option is ignored for non-binary files. This is very annoying, and I always have to remember to manually type the ^M at the end of each line! Is there some way I can force it to accept DOS-style line endings in binary mode, or force it to listen to the EOL option in text mode?

© Stack Overflow or respective owner

Related posts about vim

Related posts about binaryfiles