gVim showing carriage return (^M) even when file mode is explicitly DOS

前端 未结 10 1408
小蘑菇
小蘑菇 2020-12-22 15:25

I\'m using gVim on Windows. My code shows ^M characters at the end of lines. I used :set ff=dos to no avail. The ^M characters remain

相关标签:
10条回答
  • 2020-12-22 15:51

    You can also run:

    :e ++ff=dos
    

    To remove the ^M: See File format – Vim Tips Wiki.

    0 讨论(0)
  • 2020-12-22 15:52

    Actually what worked for me (on 64-bit windows, gVIM: 7.2 ) was:

    :set ffs=dos
    

    not just: ff

    0 讨论(0)
  • 2020-12-22 15:55

    You can ignore these chars!

    put this into your vimrc

    match Ignore /\r$/

    0 讨论(0)
  • 2020-12-22 15:57

    Running Vim 7.3 on Windows 7. I used the following command:

    :%s/^M/\r/g
    

    To create the ^M I typed in CTRL+Q then CTRL+M.

    0 讨论(0)
  • 2020-12-22 16:02

    tried a lot of things but the following worked

    :%s/\r/\r/g
    

    note: use g if you want the effect on the whole file

    0 讨论(0)
  • 2020-12-22 16:12

    I usually use the following to cleanup my line endings:

    :g/^M$/s///
    

    To get the ctrl-M I usually type ctrl-Q, then ctrl-M and it puts it in. (In some environments it may be ctrl-V then ctrl-M.) I don't know why, but I find that one easier to remember than rq's.

    Don't forget to do :set ff=dos as well, or you'll end up saving with UNIX line endings still.

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