^M at the end of every line in vim

前端 未结 9 1886
独厮守ぢ
独厮守ぢ 2020-11-29 17:37

When I am editing source files using vim and other editors sometimes at the end of the line I get these ^M characters at the end of each line. I think that it has something

相关标签:
9条回答
  • 2020-11-29 18:32

    mcedit: shift+f2, set unix format (LF), ok

    0 讨论(0)
  • 2020-11-29 18:33

    I tend to run afflicted files through fromdos before reopening them. fromdos is part of the tofrodos package.

    0 讨论(0)
  • 2020-11-29 18:37
    " put this in your ~/.vimrc file and :source ~/.vimrc
    " then you can do: Dos2Unix
    " dos2unix ^M
    fun! Dos2unixFunction()
        let _s=@/
        let l = line(".")
        let c = col(".")
        try
            set ff=unix
            w!
            "%s/\%x0d$//e
        catch /E32:/
            echo "Sorry, first save the file."
        endtry
        let @/=_s
        call cursor(l, c)
    endfun
    com! Dos2Unix keepjumps call Dos2unixFunction()
    
    0 讨论(0)
提交回复
热议问题