使用vim处理文本文件中的\ r \ n ^ M ^ @ [英] Dealing with \r \n ^M ^@ in text files using vim
问题描述
当我将excel文件中的数据行另存为制表符分隔的.txt文件,然后在VIM中打开这些文件时,我发现原来是excel中的多行文件现在变成了VIM中的单行文件. /p>
可以使用一些替换命令在VIM中分隔行":
%s/^M/\r\n/g
此后,行"现在由^@
分隔.
我使用另一个替换命令来处理它:
%s/^@//g
我的问题是:
- 为什么我的多行txt Excel文件在VI中单行打开?
- 什么是
^@
? - 是否有更好的方法来修复"我的txt文件?
尝试以下命令:
:%s/^M/\r/g
\r
是vim使用的回车符. ^M
字符是按实际显示的换行符.
When I save lines of data in excel files as tab delimited .txt files, and then open those files in VIM, I see that what was once a multi-line file in excel is now a single line file in VIM.
The "lines" can be separated in VIM using some substitution commands:
%s/^M/\r\n/g
After this, the "lines" are now separated by an ^@
.
I deal with it using another substitution command:
%s/^@//g
My questions are:
- Why do my multi-line txt excel files open as a single line in VI?
- What is
^@
? - Is there a better way to 'fix' my txt files?
Try this command:
:%s/^M/\r/g
\r
is the carriage return character vim uses. The ^M
character is a newline character that is literally displayed.
这篇关于使用vim处理文本文件中的\ r \ n ^ M ^ @的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!