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

后端 未结 2 658
难免孤独
难免孤独 2021-01-13 11:50

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 d

相关标签:
2条回答
  • 2021-01-13 12:16

    Try this:

    :set fileformat=unix
    

    Can't really verify it though, since I don't have that kind of files handy.

    0 讨论(0)
  • 2021-01-13 12:23

    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.

    0 讨论(0)
提交回复
热议问题