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

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


当前回答

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

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

其他回答

首先,使用:set ff?来确定文件的格式。

我猜可能是unix,那么问题是你的文件是用fileformat=dos创建的,在行末添加“^M^J”,但用flieformat=unix读取,只从行末删除“^J”,留下“^M”。

只需在Vim命令行中输入:e++ ff=dos即可将文件格式从unix更改为dos。这应该能解决问题。如果不是,:%s/\r//g会帮助你。

在windows下,尝试:%s/<C-Q><C-M>/g

:g/^M/s// /g

如果你用Shift+6 Caps+M输入^M,它不会接受。

你需要输入ctrl+v ctrl+m。

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

s/^M//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()