Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit a file in Vim with all lines ending in ^M except the last line ending in ^M^J

Tags:

vim

I have a bunch of files that I need to look at. All lines in these files end in ^M (\x0D) except the very last line that ends in ^M^J (\x0D\x0A).

Obviously, Vim determines the filetype to be DOS with the effect that the file's entire content is displayed on one single line like so:

some text foo^Mmore text and^Ma few control-m^Ms and more and more

Since I don't want to change the files' content: is there a setting in Vim that allows to look at these files with the new lines as I'd expect them to be?

like image 322
René Nyffenegger Avatar asked Nov 05 '22 04:11

René Nyffenegger


1 Answers

If you do not mind having a line at the bottom containing a single ^J character, you can set fileformats (note the s at the end) to mac and reload the buffer:

:set fileformats=mac
:edit

Or equivalently you could start the editor as follows:

vim -R "+set fileformats=mac" "+edit" <filename>

The -R (readonly) option is there because you stated you do not want to change the files.

I did not find a way that does not involve reloading the buffer.

like image 61
heijp06 Avatar answered Nov 15 '22 05:11

heijp06