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

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


当前回答

这是唯一对我有效的方法:

: ff + + =

可以在http://vim.wikia.com/wiki/File_format找到它

其他回答

sed s/^M//g file1.txt > file2.txt

其中^M是通过同时按下3个键,ctrl + v + M

这个函数保存跳转列表

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()

使用以下命令之一:

:%s/\r//g

Or

:%s/\r\(\n\)/\1/g

这是唯一对我有效的方法:

: ff + + =

可以在http://vim.wikia.com/wiki/File_format找到它

在串行控制台上,所有的vi和sed解决方案都不适合我。我不得不:

cat inputfilename | tr -d '\r' > outputfilename