Vim在每一行结束时显示^M。

我如何用在Vim中打开的文件中的普通换行符替换它?


当前回答

我用sed做了这个:

Sed -i -e 's/\r/\n/g'文件名

其他回答

^M是由Ctrl+V和M检索的

s/^M//g

我用sed做了这个:

Sed -i -e 's/\r/\n/g'文件名

这个函数保存跳转列表

fun! Dos2unixFunction()
let _s=@/
let l = line(".")
let c = col(".")
try
    set ff=unix
    w!
    "%s/\%x0d$//e
catch /E32:/
    echo "Sorry, the file is not saved."
endtry
let @/=_s
call cursor(l, c)
endfun
com! Dos2Unix keepjumps call Dos2unixFunction()

在Solaris:

: %。s /; rolelabel CTRL + V > 50%的CTRL + M / / g

那就是:

: % s / M ^ / / g

这意味着:

% =所有行, S =代入, ^M =你想要替换的东西 // =替换为空 G =全局(不仅是第一次出现)

或者不使用vim,只需使用此命令修复换行符

fromdos <filename.txt>

希望能有所帮助!