0

When I edit a file in vim or nano on multiple terminal emulators it is adding a line feed to my files.

xxd of file before edit:

00001880: 5645 5574 4c53 3074 4c51 6f3d            VEUtLS0tLQo=

xxd of file after an edit, save but no changes (made by me) to the file:

00001880: 5645 5574 4c53 3074 4c51 6f3d 0a         VEUtLS0tLQo=.

I thought you could use :set list in vim and then remove the line feed. That does not seem to be the case. Vim is displaying a $ at the end of each line, however I am unable to see the LF and remove it. I have also tried :set binary, :set ++ffs=unix, sed -i 's/\r$//' file and other options. What am I missing here?

choroba
  • 231,213
  • 25
  • 204
  • 289

2 Answers2

1

I think that the option that you need is this

:set nofixendofline

you can include the option in the .vimrc file

" .vimrc file

autocmd Filetype <your-filetype> set nofixendofline

you can find more information here https://stackoverflow.com/a/16114535/4681320

0

This is probably because of the way textfiles are defined in Unix. More specifically, a POSIX "text file" must end in a newline (or be an empty file).

To quote the POSIX definition:

3.403 Text File

A file that contains characters organized into zero or more lines. [...]

3.206 Line

A sequence of zero or more non- characters plus a terminating character.

That is, whenever Vim saves the file, it appends a newline.

See also: Why should text files end with a newline?

As a commenter points out, solutions are discussed here: How to stop vim from adding a newline at end of file?

Lover of Structure
  • 1,561
  • 3
  • 11
  • 27