<?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>Straw Dogs &#187; Category List @ Straw Dogs</title>
	<atom:link href="http://www.straw-dogs.co.uk/category/vim/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.straw-dogs.co.uk</link>
	<description>The Tao of Ruby, Python, and....Straw Dogs?</description>
	<lastBuildDate>Tue, 15 Nov 2011 06:47:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Comment Multiple Lines in Vim</title>
		<link>http://www.straw-dogs.co.uk/01/05/comment-multiple-lines-in-vim/</link>
		<comments>http://www.straw-dogs.co.uk/01/05/comment-multiple-lines-in-vim/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 22:19:39 +0000</pubDate>
		<dc:creator>KingOfThisHereBlog</dc:creator>
				<category><![CDATA[vim]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.straw-dogs.co.uk/?p=562</guid>
		<description><![CDATA[Earlier today I was asked how to comment out multiple lines in Vim. Unfortunately I wasn&#8217;t too sure what the best way was and the only one I knew felt less than friendly. Anyway &#8211; after some research I&#8217;ve nailed a few different methods and thought I&#8217;d post them here for people to choose their [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-564" title="Oh Look - The Vim Logo" src="http://www.straw-dogs.co.uk/wp-content/uploads/2010/01/vim_logo.png" alt="Oh Look - The Vim Logo" width="128" height="128" />Earlier today I was asked how to comment out multiple lines in Vim. Unfortunately I wasn&#8217;t too sure what the best way was and the only one I knew felt less than friendly. Anyway &#8211; after some research I&#8217;ve nailed a few different methods and thought I&#8217;d post them here for people to choose their favourite one.</p>
<h2>1. Visual Insert</h2>
<p>This is the simplest method by far. Quick fire steps are:</p>
<ol>
<li>Ctrl + V (enter block-visual selection mode)</li>
<li>Select the first character of the lines you want to comment out using &#8220;hjkl&#8221; or cursor keys</li>
<li>Shift + i</li>
<li>Type your comment marker: &#8220;//&#8221;, &#8220;#&#8221;, etc.</li>
<li>Escape</li>
<li>The end &#8211; there is a tiny delay as the comments are now put into your other lines.</li>
</ol>
<h2>2. Visual Search/Replace</h2>
<p>This is similar to the above but has a slightly more arcane method to adding the comments.</p>
<ol>
<li>Shift + V (enter line selection mode)</li>
<li>Select the lines you want to comment out.</li>
<li>Type:</li>
</ol>
<pre>:s/^/# [Return]</pre>
<p>or</p>
<pre>:s/^/\/\/ [Return]</pre>
<p>The first will replace the the beginning of the line (^) with a hash (#) and the second will do the same with a double slash (//). Note the extra slashes to escape.</p>
<h2>3 Line Number Range</h2>
<p>Similar to above this is the only method I could think of and its hardly very friendly but it gets the job done.</p>
<p>Pick the line numbers of the first and last lines you want commented &#8211; this is rarely simple.</p>
<p>Type:</p>
<pre>:2,10s/^/#</pre>
<p>That will put hash comments at the start of lines 2 to 10.</p>
<h2>4. Using Markers</h2>
<p>I&#8217;m not fond of this method as I&#8217;m still not 100% on markers. In fact I&#8217;m around about&#8230;..0% on markers as I&#8217;d not heard of them until now!! Woo for learning!</p>
<p>Anyway &#8211; markers. Oh yes, I&#8217;ll do a nice list of steps again:</p>
<ol>
<li>On the first line while in command mode type &#8220;ma&#8221; (no colon required here)</li>
<li>Go to the last line of your intended block.</li>
<li>Type:</li>
</ol>
<pre>:'a,. s/^/# /</pre>
<p>In English that means: Form marker &#8220;a&#8221; to here (.) perform this command: s/^/# /</p>
<h2>5. Plugins</h2>
<p>You could just skip all that and install a Vim plugin. The advantage being they have more features. The disadvantage being you&#8217;d have to make sure all the servers you use have this plugin otherwise you&#8217;re stumped.</p>
<ul>
<li><a href="http://www.vim.org/scripts/script.php?script_id=1528">comments.vim</a></li>
<li><a href="http://www.vim.org/scripts/script.php?script_id=4">ToggleCommentify.vim</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.straw-dogs.co.uk/01/05/comment-multiple-lines-in-vim/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

