vim settings newline
Updated Mon, 15 Aug 2022 10:32:56 GMT

How to stop vim from adding a newline at end of file?

So I work in a PHP shop, and we all use different editors, and we all have to work on Windows. I use vim, and everyone in the shop keeps complaining that whenever I edit a file there is a newline at the bottom. I've searched around and found that this is a documented behavior of vi & vim... but I was wondering if there was some way to disable this feature. (It would be best if I could disable it for specific file extensions).

If anyone knows about this, that would be great!


And for vim 7.4+ you can use (preferably on your .vimrc) (thanks to for that last bit of news!):

:set nofixendofline

Now regarding older versions of vim.

Even if the file was already saved with new lines at the end:

vim -b file and once in vim:

:set noeol


alternatively you can open files in vim with :e ++bin file

Yet another alternative:

:set binary
:set noeol

see more details at Why do I need vim in binary mode for 'noeol' to work?

Comments (5)

  • +7 – You also can add set binary and set noeol in your .vimrc — Sep 04, 2014 at 12:59  
  • +0Beware: binary overrides expandtab, which will lead you to get literal tabs in your source. — Feb 13, 2015 at 10:32  
  • +5 – @CiroSantilli thank you! i've been looking for side effects of binary forever and wondering why it is not the default! since i love my tabs, i think i will consider that added benefit :) — Mar 13, 2015 at 18:09  
  • +0 – Now you could add set nofixendofline to solve the problem in Vim 7.4+ — Jun 24, 2017 at 16:38  
  • +1 – @TrevorBoydSmith yes, because historically POSIX (i might be wrong on the actual standard) expect a new line at the end of a line, in a text file. That's why most solutions required treating it as a binary. It probably was very convenient then, and It's backward today, that's why now there's the convenient setting. Just add it to your vimrc. There are worse problems in other editors anyway :) — May 02, 2019 at 01:42