zoukankan      html  css  js  c++  java
  • What is `^M` and how do I get rid of it?

    When I open the file in vim, I am seeing strange ^M characters.

    Unfortunately, the world's favorite search engine does not do well with special characters in queries, so I'm asking here:

    • What is this ^M character?

    • How could it have gotten there?

    • How do I get rid of it?

    he ^M is a carriage-return character. If you see this, you're probably looking at a file that originated in the DOS/Windows world, where an end-of-line is marked by a carriage return/newline pair, whereas in the Unix world, end-of-line is marked by a single newline.

    A simpler way to do this is to use the following command:(需要安装该工具:yum install dos2unix)
    dos2unix filename
    This command works with path patterns as well, Eg
    dos2unix path/name*
    If it doesn't work, try using different mode:
    dos2unix -c mac filename
    -c Set conversion mode. Where CONVMODE is one of: ascii, 7bit, iso, mac with ascii being the default.
     
    其它方法:
    :e ++ff=dos 
    

    The :e ++ff=dos command tells Vim to read the file again, forcing dos file format. Vim will remove CRLF and LF-only line endings, leaving only the text of each line in the buffer.

    then

    :set ff=unix 
    

    and finally

    :wq 
    
  • 相关阅读:
    nyist_21(三个水杯)(BFS)
    寒假刷题之普通之红与黑
    寒假刷题之普通之变形课
    寒假刷题之普通之最小差
    什么是 Spring Boot
    择业十诫----与内心的渴望同行
    模式窗体中调用父页面Javascript
    二级域名解析
    软件测试
    网狐系统介绍
  • 原文地址:https://www.cnblogs.com/rusking/p/10575794.html
Copyright © 2011-2022 走看看