<?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>The Educated New Village Boy &#187; vi</title>
	<atom:link href="http://envb.sapphirewillow.com/writings/tag/vi/feed/" rel="self" type="application/rss+xml" />
	<link>http://envb.sapphirewillow.com/writings</link>
	<description>Taglines encourage pigeonholing</description>
	<lastBuildDate>Fri, 31 Dec 2010 03:18:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>My most commonly used VIM commands</title>
		<link>http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/</link>
		<comments>http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 05:40:36 +0000</pubDate>
		<dc:creator>feicipet</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[vi]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://envb.sapphirewillow.com/writings/?p=43</guid>
		<description><![CDATA[I wrote this as a response to a VI question in LowYat forums. Hope it&#8217;s useful to someone else out there. :$ - Move to the last line (why this instead of shift-G? read below) :10 - Move to line no 10, just substitute with any other number. So, just remember &#8220;$&#8221; means &#8220;last line&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote this as a response to a VI question in <a href="http://forum.lowyat.net/index.php?showtopic=1087617&amp;view=findpost&amp;p=27113127">LowYat forums</a>. Hope it&#8217;s useful to someone else out there.</p>
<ol>
<li><span style="color: red;"><span style="font-family: Courier;">:$</span> </span>- Move to the last line (why this instead of shift-G? read below)</li>
<li><span style="color: red;"><span style="font-family: Courier;">:10</span> </span>- Move to line no 10, just substitute with any other number. So, just remember &#8220;$&#8221; means &#8220;last line&#8221; and you will find it more intuitive.</li>
<li><span style="color: red;"><span style="font-family: Courier;">:0,$ s/replace this/with this/g</span> </span>- Literally, it means &#8220;from lines 0 to last line ($), search for &#8220;replace this&#8221; and replace with &#8220;with this&#8221;. If you want you can just change the range, for e.g. &#8220;2,10&#8243; to mean lines 2 to 10. If you omit the &#8220;g&#8221; at the end of the command, it means only replace the first instance that vim encounters on a particular line. With &#8220;g&#8221;, it will replace all instances. Try &#8220;:0,$ s/hello/goodbye/g&#8221; and &#8220;:0,$ s/hello/goodbye/&#8221; on a file that has &#8220;hello Sam hello Delilah&#8221; to see how this works.</li>
<li><span style="color: red;"><span style="font-family: Courier;">v</span> </span>- Type the character &#8220;v&#8221; and start moving your cursor around. You&#8217;ll see that it highlights an entire block, readying a selection for you to do cut n paste (see below for cut n paste)</li>
<li><span style="color: red;"><span style="font-family: Courier;">shift-v</span> </span>- Does the same as &#8220;v&#8221; but for whole lines</li>
<li><span style="color: red;"><span style="font-family: Courier;">ctrl-v</span> </span>- Does the same as &#8220;v&#8221; but in arbitrary block mode (hard to explain, try and you&#8217;ll know)</li>
<li>To copy, first highlight a selection of text using any instruction from 4-6. Then press <span style="color: red;"><span style="font-family: Courier;">&#8220;ay</span> </span>(with the double quote). The selection will disappear. Move your cursor some where else. Then press <span style="color: red;"><span style="font-family: Courier;">&#8220;ap</span> </span>.</li>
<li>To cut, do the same as &#8220;7&#8243; but substitute <span style="color: red;"><span style="font-family: Courier;">&#8220;ay</span> </span>with <span style="color: red;"><span style="font-family: Courier;">&#8220;ax</span> </span>.</li>
<li>All the copy n paste shit above is nice, but has been rendered obsolete by modern terminal emulators that allow you to use a mouse to highlight and copy/paste. But this is why I still use this trick. After you have done either 7 or 8, do NOT quit the editor, but highlight another block of text using any instruction from 4-6. Now type <span style="color: red;"><span style="font-family: Courier;">&#8220;by</span> </span>. Now move your cursor somewhere else and type <span style="color: red;"><span style="font-family: Courier;">&#8220;bp</span> </span>. Now type <span style="color: red;"><span style="font-family: Courier;">&#8220;ap</span> </span>again. You will see that the text that you copied using <span style="color: red;"><span style="font-family: Courier;">&#8220;ay</span> </span>and <span style="color: red;"><span style="font-family: Courier;">&#8220;by</span></span>have actually been stored into different buffers (or &#8220;registers&#8221; in VIM convention). You can declare many more registers just by swapping &#8220;a&#8221; and &#8220;b&#8221; with &#8220;c&#8221; or &#8220;d&#8221; or&#8230; you get the idea.</li>
<li>And finally, remember that you can tell vim to perform a command X times very easily. For e.g., highlight a line and type <span style="color: red;"><span style="font-family: Courier;">&#8220;ay</span></span> to copy into register &#8220;a&#8221;. Then type <span style="color: red;"><span style="font-family: Courier;">10&#8243;ap</span></span>. You will see that it has pasted register &#8220;a&#8221; 10 times. Cool, huh? Just prepend your command with a number to tell vim to run it that number of times.</li>
</ol>
<p>Note that these tricks work mostly with VIM (VI Improved), not plain vi.</p>
<p>In (K)Ubuntu, only a minimal build of vim is installed by default. To upgrade it, just type &#8220;sudo aptitude install vim&#8221;. You should know which version you&#8217;re using pretty easily. Just edit a shell script, if there&#8217;s no syntax highlighting, it means you don&#8217;t have the full VIM installed. Otherwise, things are cool.</p>
<!-- Social Bookmarking Reloaded BEGIN --><div class="social_bookmark"><em>Sharing is caring</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/&amp;title=My+most+commonly+used+VIM+commands" title="Add 'My most commonly used VIM commands' to Del.icio.us"><img src="http://envb.sapphirewillow.com/writings/wp-content/plugins/social-bookmarking-reloaded/delicious.png" title="Add 'My most commonly used VIM commands' to Del.icio.us" alt="Add 'My most commonly used VIM commands' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/&amp;title=My+most+commonly+used+VIM+commands" title="Add 'My most commonly used VIM commands' to digg"><img src="http://envb.sapphirewillow.com/writings/wp-content/plugins/social-bookmarking-reloaded/digg.png" title="Add 'My most commonly used VIM commands' to digg" alt="Add 'My most commonly used VIM commands' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/&amp;title=My+most+commonly+used+VIM+commands" title="Add 'My most commonly used VIM commands' to reddit"><img src="http://envb.sapphirewillow.com/writings/wp-content/plugins/social-bookmarking-reloaded/reddit.png" title="Add 'My most commonly used VIM commands' to reddit" alt="Add 'My most commonly used VIM commands' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/" title="Add 'My most commonly used VIM commands' to Technorati"><img src="http://envb.sapphirewillow.com/writings/wp-content/plugins/social-bookmarking-reloaded/technorati.png" title="Add 'My most commonly used VIM commands' to Technorati" alt="Add 'My most commonly used VIM commands' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/&amp;title=My+most+commonly+used+VIM+commands" title="Add 'My most commonly used VIM commands' to Stumble Upon"><img src="http://envb.sapphirewillow.com/writings/wp-content/plugins/social-bookmarking-reloaded/stumbleupon.png" title="Add 'My most commonly used VIM commands' to Stumble Upon" alt="Add 'My most commonly used VIM commands' to Stumble Upon" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/&amp;title=My+most+commonly+used+VIM+commands" title="Add 'My most commonly used VIM commands' to Google Bookmarks"><img src="http://envb.sapphirewillow.com/writings/wp-content/plugins/social-bookmarking-reloaded/google.png" title="Add 'My most commonly used VIM commands' to Google Bookmarks" alt="Add 'My most commonly used VIM commands' to Google Bookmarks" /></a><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.bloglines.com/sub/http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/" title="Add 'My most commonly used VIM commands' to Bloglines"><img src="http://envb.sapphirewillow.com/writings/wp-content/plugins/social-bookmarking-reloaded/bloglines.png" title="Add 'My most commonly used VIM commands' to Bloglines" alt="Add 'My most commonly used VIM commands' to Bloglines" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?title=My+most+commonly+used+VIM+commands&amp;url=http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/" title="Add 'My most commonly used VIM commands' to SlashDot"><img src="http://envb.sapphirewillow.com/writings/wp-content/plugins/social-bookmarking-reloaded/slashdot.png" title="Add 'My most commonly used VIM commands' to SlashDot" alt="Add 'My most commonly used VIM commands' to SlashDot" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/&amp;t=My+most+commonly+used+VIM+commands" title="Add 'My most commonly used VIM commands' to FaceBook"><img src="http://envb.sapphirewillow.com/writings/wp-content/plugins/social-bookmarking-reloaded/facebook.png" title="Add 'My most commonly used VIM commands' to FaceBook" alt="Add 'My most commonly used VIM commands' to FaceBook" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://blogsvine.com/submit.php?url=http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/" title="Add 'My most commonly used VIM commands' to Blogsvine"><img src="http://envb.sapphirewillow.com/writings/wp-content/plugins/social-bookmarking-reloaded/blogsvine.png" title="Add 'My most commonly used VIM commands' to Blogsvine" alt="Add 'My most commonly used VIM commands' to Blogsvine" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/" title="Add 'My most commonly used VIM commands' to Twitter"><img src="http://envb.sapphirewillow.com/writings/wp-content/plugins/social-bookmarking-reloaded/twitter.png" title="Add 'My most commonly used VIM commands' to Twitter" alt="Add 'My most commonly used VIM commands' to Twitter" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/reader/link?url=http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/&amp;title=My+most+commonly+used+VIM+commands&amp;srcURL=http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/" title="Add 'My most commonly used VIM commands' to Google Buzz"><img src="http://envb.sapphirewillow.com/writings/wp-content/plugins/social-bookmarking-reloaded/googlebuzz.png" title="Add 'My most commonly used VIM commands' to Google Buzz" alt="Add 'My most commonly used VIM commands' to Google Buzz" /></a></div>
<!-- Social Bookmarking Reloaded END -->]]></content:encoded>
			<wfw:commentRss>http://envb.sapphirewillow.com/writings/2009/07/my-most-commonly-used-vim-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

