如何删除 ^M 并使行回到 vim 中的上一行
How to remove ^M and make line back to the previous line in vim
我有一个 .txt 文件,它是来自某个来源的转储 -table,以制表符分隔的形式。
提到的 source-table 中的一些单元格本身包含带有换行符的文本。当我打开转储(一个 .txt 文件)时,事实证明这些换行符显示为 ^M\
字符序列 - 它们在我的转储 .txt 文件中具有 "real" 换行符,因此使转储 .txt 文件混乱结构体。
我想从文件中删除它们(我不关心这些源-table 单元格中的内容)并使用了:
:%s/\r\//g
制作这样的片段:
20 20 id_20_foo_text_part1 ^M\
21 id_20_foo_text_part2^M\
22 id_20_foo_text_part3
23 21 id_21_foo_text
(第一列是vim编辑行号,第二列是实际值(一些id))
转换为:
20 20 id_20_foo_text_part1
21 id_20_foo_text_part2
22 id_20_foo_text_part3
23 21 id_21_foo_text
而我想:
20 20 id_20_foo_text_part1 id_20_foo_text_part2 id_20_foo_text_part3
21 21 id_21_foo_text
问:如何去掉^M\
,让"undesiredly newlined"行回到上一行?
在正则表达式的末尾添加换行符 (\n
)。像这样:
:%s/\^M\\n//g
只需将您的 :%s/\r\//g
更改为 :%s/\r\\n//
- 在
\
后面加一个\n
,做“join
”操作
g
没有多大意义。
我有一个 .txt 文件,它是来自某个来源的转储 -table,以制表符分隔的形式。
提到的 source-table 中的一些单元格本身包含带有换行符的文本。当我打开转储(一个 .txt 文件)时,事实证明这些换行符显示为 ^M\
字符序列 - 它们在我的转储 .txt 文件中具有 "real" 换行符,因此使转储 .txt 文件混乱结构体。
我想从文件中删除它们(我不关心这些源-table 单元格中的内容)并使用了:
:%s/\r\//g
制作这样的片段:
20 20 id_20_foo_text_part1 ^M\
21 id_20_foo_text_part2^M\
22 id_20_foo_text_part3
23 21 id_21_foo_text
(第一列是vim编辑行号,第二列是实际值(一些id))
转换为:
20 20 id_20_foo_text_part1
21 id_20_foo_text_part2
22 id_20_foo_text_part3
23 21 id_21_foo_text
而我想:
20 20 id_20_foo_text_part1 id_20_foo_text_part2 id_20_foo_text_part3
21 21 id_21_foo_text
问:如何去掉^M\
,让"undesiredly newlined"行回到上一行?
在正则表达式的末尾添加换行符 (\n
)。像这样:
:%s/\^M\\n//g
只需将您的 :%s/\r\//g
更改为 :%s/\r\\n//
- 在
\
后面加一个\n
,做“join
”操作 g
没有多大意义。