<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>acloudtree &#187; ^</title>
	<atom:link href="http://www.acloudtree.com/tag/431/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.acloudtree.com</link>
	<description>Programming, Computers, Writing, Economics, and Life</description>
	<lastBuildDate>Tue, 07 Feb 2012 00:03:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>(Nerd) ^M Removing control characters using VIM</title>
		<link>http://www.acloudtree.com/nerd-m-removing-control-characters-using-vim/</link>
		<comments>http://www.acloudtree.com/nerd-m-removing-control-characters-using-vim/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 05:31:53 +0000</pubDate>
		<dc:creator>jared.folkins</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[VIM]]></category>
		<category><![CDATA[character]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[M]]></category>
		<category><![CDATA[^]]></category>

		<guid isPermaLink="false">http://www.acloudtree.com/?p=566</guid>
		<description><![CDATA[hat tip Matthew Turland Have you ever opened up a file using VI and found the following? &#60;?php echo '&#60;html&#62;'^M echo '&#60;head&#62;'^M echo '&#60;/head&#62;'^M echo '&#60;body&#62;'^M &#160; ... That stupid control character from some other horrid text editor is trailing every single line. And you are annoyed enough to Google for an answer. ^M Now, [...]]]></description>
			<content:encoded><![CDATA[<p><em>hat tip </em><em><a href="http://matthewturland.com/">Matthew Turland</a></em></p>
<p>Have you ever opened up a file using VI and found  the following?</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;html&gt;'</span>^M
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;head&gt;'</span>^M
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/head&gt;'</span>^M
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;body&gt;'</span>^M
&nbsp;
<span style="color: #339933;">...</span></pre></div></div>

<p>That stupid control character from some other horrid text editor is trailing every single line. And you are annoyed enough to Google for an answer. ^M</p>
<p>Now, hopefully you are aware of the powerful regex tools built right into VI. But in this case, the fix is pretty simple, and we won&#8217;t have to craft any regFu. After you open your file using VI, we will then use the search/replace functionality. And we will eventually end up with a line that looks like this.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:<span style="color: #000000; font-weight: bold;">%</span>s<span style="color: #000000; font-weight: bold;">/</span>^M<span style="color: #000000; font-weight: bold;">//</span>g</pre></div></div>

<p>But there is a gotcha to this solution, so you may need to read on to find out more. And before proceeding, press esc to make sure you are not in insert mode.</p>
<p>First type the following.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> Shift + :</pre></div></div>

<p>Which should just print the colon at the bottom of your screen.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:</pre></div></div>

<p>Then type this exactly how it looks.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span>s<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Now we need to type the control character.  You may be thinking &#8220;Jared, I will just hit shift + 6 and get that character onto my screen in no time.&#8221;. And you are more than welcome to do that, but you would be wrong.</p>
<p>You will need to press the following keys.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Control + V</pre></div></div>

<p>Which will get you this printed out.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:<span style="color: #000000; font-weight: bold;">%</span>s<span style="color: #000000; font-weight: bold;">/</span>^</pre></div></div>

<p>Then type the following.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Control + M</pre></div></div>

<p>Which should have you ending up with this.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:<span style="color: #000000; font-weight: bold;">%</span>s<span style="color: #000000; font-weight: bold;">/</span>^M</pre></div></div>

<p>At this point you can type the rest of the characters exactly how they look.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">//</span>g</pre></div></div>

<p>Which leaves you with a finished line that looks like so.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:<span style="color: #000000; font-weight: bold;">%</span>s<span style="color: #000000; font-weight: bold;">/</span>^M<span style="color: #000000; font-weight: bold;">//</span>g</pre></div></div>

<p>Press enter, and you will now replace the ^M character with nothing.</p>
<p></p>
<p><strong>Part 2(kinda): Small search and replace example.</strong></p>
<p>This would replace Dog with Cat.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:<span style="color: #000000; font-weight: bold;">%</span>s<span style="color: #000000; font-weight: bold;">/</span>Dog<span style="color: #000000; font-weight: bold;">/</span>Cat<span style="color: #000000; font-weight: bold;">/</span>g</pre></div></div>

<p>Cat with Mouse.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:<span style="color: #000000; font-weight: bold;">%</span>s<span style="color: #000000; font-weight: bold;">/</span>Cat<span style="color: #000000; font-weight: bold;">/</span>Mouse<span style="color: #000000; font-weight: bold;">/</span>g</pre></div></div>

<p>Mouse with Trap.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:<span style="color: #000000; font-weight: bold;">%</span>s<span style="color: #000000; font-weight: bold;">/</span>Mouse<span style="color: #000000; font-weight: bold;">/</span>Trap<span style="color: #000000; font-weight: bold;">/</span>g</pre></div></div>

<p>So our line to replace the ^M character is literally saying &#8220;Replace the ^M character with nothing&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acloudtree.com/nerd-m-removing-control-characters-using-vim/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

