My recipe for saving files in vim without the end of file newline is:
:set binary
:set noeol
:wqThe fact that noeol does nothing without binary mode is weird on itself. But reading the :help binary i'm still unsure of somethings there.
When this option is switched on a few options will be changed (also when it already was on): 'textwidth' will be set to 0 'wrapmargin' will be set to 0 'modeline' will be off 'expandtab' will be off Also, 'fileformat' and 'fileformats' options will not be used, the file is read and written like 'fileformat' was "unix" (a single <NL> separates lines). The 'fileencoding' and 'fileencodings' options will not be used, the file is read without conversion. NOTE: When you start editing a(nother) file while the 'bin' option is on, settings from autocommands may change the settings again (e.g., 'textwidth'), causing trouble when editing. You might want to set 'bin' again when the file has been loaded.
i can still see UTF8 chars, so fileencoding is not totally gone. I never used expandtab (use tabs to ident, but even if i didn't, expandtabs is just wrong). But besides that, what else could happen in practice?
i'm tired of that new line at the end of files and considering opening all files in binary mode and with noeol set by default. Am I in for lots of trouble?
51 Answer
If you don't encounter arbitrary encodings (i.e. either all ASCII or the encoding matching your Vim's), and aren't bothered by the ^M in files with Window file endings, you approach should work just fine.
Vim wasn't meant to edit such files (the Unix standpoint is they are incomplete), therefore it's hard to do. However, my PreserveNoEOL plugin tries to make that more comfortable, so you don't have to worry about the mechanics.
1