使用vim处理文本文件中的\ r \ n ^ M ^ @ [英] Dealing with \r \n ^M ^@ in text files using vim

查看:520
本文介绍了使用vim处理文本文件中的\ r \ n ^ M ^ @的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将excel文件中的数据行另存为制表符分隔的.txt文件,然后在VIM中打开这些文件时,我发现原来是excel中的多行文件现在变成了VIM中的单行文件. /p>

可以使用一些替换命令在VIM中分隔行":

%s/^M/\r\n/g

此后,行"现在由^@分隔. 我使用另一个替换命令来处理它:

%s/^@//g

我的问题是:

  1. 为什么我的多行txt Excel文件在VI中单行打开?
  2. 什么是^@?
  3. 是否有更好的方法来修复"我的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:

  1. Why do my multi-line txt excel files open as a single line in VI?
  2. What is ^@?
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆