regex in vim to clear the trailing character

December 6th, 2006 mysurface Posted in Text Manipulation, vi, vim | Hits: 32854 | 1 Comment »

Sometimes, the file created at windows may tag alone the trailing character at the end of every line, where user press enter. It may shows as ^M. It is very irritating! to clear it off is very easy in vim.


%s is global search, change effect on every lines, \s is space \s* is to search for one or more space or no space, \r* is one or more or none carry return, $ indicate \s*\r* must appear at the end of the line, // means nothing. So searching for trailing character which we don’t want and replace with nothing.

It can be written as


Donno vim? Learn it up, refers to this post. It is very to learn up, the requirement is you have to learn it and use it often.

One Response to “regex in vim to clear the trailing character”

  1. “Why Quotes?

Leave a Reply