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

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


当前回答

另外,还有称为dos2unix和unix2dos的开源实用程序可以做这件事。在linux系统上,它们可能是默认安装的;对于Windows系统,你可以从http://www.bastet.com/等网站下载。

其他回答

在Solaris:

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

那就是:

: % s / M ^ / / g

这意味着:

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

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

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

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

s/^M//g

在vim中,使用命令:

: % s / \ r \ n \ r / g

想要搜索和替换的地方:

\ r \ n

into

\r

/g

是全球性的

注意,这与@ContextSwitch的答案相同,但带有全局标志

这个函数保存跳转列表

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