Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make vim show ^M and substitute it

Tags:

regex

vim

my vim show tab as --->, but does not show windows ^M character.

And , how substitute it in vim.

renew ============

I check my vimrc it is set fileformat=unix but when I open a dos file set ff is dos

like image 290
guilin 桂林 Avatar asked Oct 04 '10 04:10

guilin 桂林


People also ask

What does M mean in vim?

0xD is the carriage return character. ^M happens to be the way vim displays 0xD (0x0D = 13, M is the 13th letter in the English alphabet). You can remove all the ^M characters by running the following: :%s/^M//g.

How do I search and replace in vim?

Basic Find and Replace In Vim, you can find and replace text using the :substitute ( :s ) command. To run commands in Vim, you must be in normal mode, the default mode when starting the editor. To go back to normal mode from any other mode, just press the 'Esc' key.

How do I get rid of M in vim?

How can I remove ^M characters from text files? A. ^M are nothing more than carriage return, so it is easy to use the search and replace function of vim to remove them. That will do the job.

How do you show control M characters in Linux?

Note: Remember how to type control M characters in UNIX, just hold the control key and then press v and m to get the control-m character.


2 Answers

Display CRLF as ^M:

:e ++ff=unix

Substitute CRLF for LF:

:setlocal ff=unix
:w
:e

like image 93
NoToR Avatar answered Sep 29 '22 05:09

NoToR


Vim does show ^M except in one case: if the fileformat=dos then it will not show a trailing crlf.

You can find out which format (unix or dos) you have by typing :set and you can get rid of the ^M in the crlf by just changing the format (:set fileformat=unix) and then writing out the file.

If you have a ^M in the middle of the line, then you should be able to see it, even in a fileformat=dos file, and you can pattern match it with \r. (Oddly, the syntax for subsituting a newline is a \r in the replacement part of the sub, so the way one changes ^M to ^N is by the not-at-all-a-noop :s/\r/\r/.)

like image 32
DigitalRoss Avatar answered Sep 29 '22 04:09

DigitalRoss