{"id":79,"date":"2018-07-25T13:16:20","date_gmt":"2018-07-25T09:16:20","guid":{"rendered":"http:\/\/kidds.co.za\/?p=79"},"modified":"2018-07-25T14:43:41","modified_gmt":"2018-07-25T10:43:41","slug":"vi-cheatsheet","status":"publish","type":"post","link":"https:\/\/kidds.co.za\/index.php\/2018\/07\/25\/vi-cheatsheet\/","title":{"rendered":"Vi Cheatsheet &#8211; Basics"},"content":{"rendered":"<h3 style=\"text-align: left;\" align=\"CENTER\">Vi Cheat Sheet &#8211; Basics<\/h3>\n<p>&nbsp;<\/p>\n<p><a name=\"mode\"><\/a><\/p>\n<h2>Modes<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table>\n<tbody>\n<tr>\n<td>Vi has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute as soon as you type them except for &#8220;colon&#8221; commands which execute when you press the ruturn key.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"quit\"><\/a><\/p>\n<h2>Quitting<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>: x<\/td>\n<td>Exit, saving changes (no space between : and x)<\/td>\n<\/tr>\n<tr>\n<td>:q<\/td>\n<td>Exit as long as there have been no changes<\/td>\n<\/tr>\n<tr>\n<td>ZZ<\/td>\n<td>Exit and save changes if any have been made<\/td>\n<\/tr>\n<tr>\n<td>:q!<\/td>\n<td>Exit and ignore any changes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"insert\"><\/a><\/p>\n<h2>Inserting Text<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>i<\/td>\n<td>Insert before cursor<\/td>\n<\/tr>\n<tr>\n<td>I<\/td>\n<td>Insert before line<\/td>\n<\/tr>\n<tr>\n<td>a<\/td>\n<td>Append after cursor<\/td>\n<\/tr>\n<tr>\n<td>A<\/td>\n<td>Append after line<\/td>\n<\/tr>\n<tr>\n<td>o<\/td>\n<td>Open a new line after current line<\/td>\n<\/tr>\n<tr>\n<td>O<\/td>\n<td>Open a new line before current line<\/td>\n<\/tr>\n<tr>\n<td>r<\/td>\n<td>Replace one character<\/td>\n<\/tr>\n<tr>\n<td>R<\/td>\n<td>Replace many characters<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"motion\"><\/a><\/p>\n<h2>Motion<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>h<\/td>\n<td>Move left<\/td>\n<\/tr>\n<tr>\n<td>j<\/td>\n<td>Move down<\/td>\n<\/tr>\n<tr>\n<td>k<\/td>\n<td>Move up<\/td>\n<\/tr>\n<tr>\n<td>l<\/td>\n<td>Move right<\/td>\n<\/tr>\n<tr>\n<td>w<\/td>\n<td>Move to next word<\/td>\n<\/tr>\n<tr>\n<td>W<\/td>\n<td>Move to next blank delimited word<\/td>\n<\/tr>\n<tr>\n<td>b<\/td>\n<td>Move to the beginning of the word<\/td>\n<\/tr>\n<tr>\n<td>B<\/td>\n<td>Move to the beginning of blank delimted word<\/td>\n<\/tr>\n<tr>\n<td>e<\/td>\n<td>Move to the end of the word<\/td>\n<\/tr>\n<tr>\n<td>E<\/td>\n<td>Move to the end of Blank delimited word<\/td>\n<\/tr>\n<tr>\n<td>(<\/td>\n<td>Move a sentence back<\/td>\n<\/tr>\n<tr>\n<td>)<\/td>\n<td>Move a sentence forward<\/td>\n<\/tr>\n<tr>\n<td>{<\/td>\n<td>Move a paragraph back<\/td>\n<\/tr>\n<tr>\n<td>}<\/td>\n<td>Move a paragraph forward<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>Move to the begining of the line<\/td>\n<\/tr>\n<tr>\n<td>$<\/td>\n<td>Move to the end of the line<\/td>\n<\/tr>\n<tr>\n<td>1G<\/td>\n<td>Move to the first line of the file<\/td>\n<\/tr>\n<tr>\n<td>G<\/td>\n<td>Move to the last line of the file<\/td>\n<\/tr>\n<tr>\n<td>nG<\/td>\n<td>Move to\u00a0nth line of the file<\/td>\n<\/tr>\n<tr>\n<td>:n<\/td>\n<td>Move to\u00a0nth line of the file<\/td>\n<\/tr>\n<tr>\n<td>fc<\/td>\n<td>Move forward to\u00a0c<\/td>\n<\/tr>\n<tr>\n<td>Fc<\/td>\n<td>Move back to\u00a0c<\/td>\n<\/tr>\n<tr>\n<td>H<\/td>\n<td>Move to top of screen<\/td>\n<\/tr>\n<tr>\n<td>M<\/td>\n<td>Move to middle of screen<\/td>\n<\/tr>\n<tr>\n<td>L<\/td>\n<td>Move to botton of screen<\/td>\n<\/tr>\n<tr>\n<td>%<\/td>\n<td>Move to associated ( ), { }, [ ]<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"delete\"><\/a><\/p>\n<h2>Deleting Text<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table>\n<tbody>\n<tr>\n<td>Almost all deletion commands are performed by typing d followed by a motion. For example, dw deletes a word. A few other deletes are:<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>x<\/td>\n<td>Delete character to the right of cursor<\/td>\n<\/tr>\n<tr>\n<td>X<\/td>\n<td>Delete character to the left of cursor<\/td>\n<\/tr>\n<tr>\n<td>D<\/td>\n<td>Delete to the end of the line<\/td>\n<\/tr>\n<tr>\n<td>dd<\/td>\n<td>Delete current line<\/td>\n<\/tr>\n<tr>\n<td>:d<\/td>\n<td>Delete current line<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"yank\"><\/a><\/p>\n<h2>Yanking Text<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table>\n<tbody>\n<tr>\n<td>Like deletion, almost all yank commands are performed by typing y followed by a motion. For example, y$ yanks to the end of the line. Two other yank commands are:<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>yy<\/td>\n<td>Yank the current line<\/td>\n<\/tr>\n<tr>\n<td>:y<\/td>\n<td>Yank the current line<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"change\"><\/a><\/p>\n<h2>Changing text<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table>\n<tbody>\n<tr>\n<td>The change command is a deletion command that leaves the editor in insert mode. It is performed by typing c followed by a motion. For wxample cw changes a word. A few other change commands are:<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>C<\/td>\n<td>Change to the end of the line<\/td>\n<\/tr>\n<tr>\n<td>cc<\/td>\n<td>Change the whole line<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"put\"><\/a><\/p>\n<h2>Putting text<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>p<\/td>\n<td>Put after the position or after the line<\/td>\n<\/tr>\n<tr>\n<td>P<\/td>\n<td>Put before the poition or before the line<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"buffer\"><\/a><\/p>\n<h2>Buffers<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table>\n<tbody>\n<tr>\n<td>Named buffers may be specified before any deletion, change, yank or put command. The general prefix has the form &#8220;c where c is any lowercase character. for example, &#8220;adw deletes a word into buffer a. It may thereafter be put back into text with an appropriate &#8220;ap.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"mark\"><\/a><\/p>\n<h2>Markers<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table>\n<tbody>\n<tr>\n<td>Named markers may be set on any line in a file. Any lower case letter may be a marker name. Markers may also be used as limits for ranges.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>mc<\/td>\n<td>Set marker\u00a0c\u00a0on this line<\/td>\n<\/tr>\n<tr>\n<td>`c<\/td>\n<td>Go to beginning of marker\u00a0c\u00a0line.<\/td>\n<\/tr>\n<tr>\n<td>&#8216;c<\/td>\n<td>Go to first non-blank character of marker\u00a0c\u00a0line.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"search\"><\/a><\/p>\n<h2>Search for strings<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>\/string<\/td>\n<td>Search forward for\u00a0string<\/td>\n<\/tr>\n<tr>\n<td>?string<\/td>\n<td>Search back for\u00a0string<\/td>\n<\/tr>\n<tr>\n<td>n<\/td>\n<td>Search for next instance of\u00a0string<\/td>\n<\/tr>\n<tr>\n<td>N<\/td>\n<td>Search for previous instance of\u00a0string<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"replace\"><\/a><\/p>\n<h2>Replace<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table>\n<tbody>\n<tr>\n<td>The search and replace function is accomplished with the :s command. It is commonly used in combination with ranges or the :g command (below).<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>:s\/pattern\/string\/flags<\/td>\n<td>Replace\u00a0pattern\u00a0with\u00a0string\u00a0according to\u00a0flags.<\/td>\n<\/tr>\n<tr>\n<td>g<\/td>\n<td>Flag &#8211; Replace all occurences of pattern<\/td>\n<\/tr>\n<tr>\n<td>c<\/td>\n<td>Flag &#8211; Confirm replaces.<\/td>\n<\/tr>\n<tr>\n<td>&amp;<\/td>\n<td>Repeat last :s command<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"re\"><\/a><\/p>\n<h2>Regular Expressions<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>. (dot)<\/td>\n<td>Any single character except newline<\/td>\n<\/tr>\n<tr>\n<td>*<\/td>\n<td>zero or more occurances of any character<\/td>\n<\/tr>\n<tr>\n<td>[&#8230;]<\/td>\n<td>Any single character specified in the set<\/td>\n<\/tr>\n<tr>\n<td>[^&#8230;]<\/td>\n<td>Any single character not specified in the set<\/td>\n<\/tr>\n<tr>\n<td>^<\/td>\n<td>Anchor &#8211; beginning of the line<\/td>\n<\/tr>\n<tr>\n<td>$<\/td>\n<td>Anchor &#8211; end of line<\/td>\n<\/tr>\n<tr>\n<td>\\&lt;<\/td>\n<td>Anchor &#8211; begining of word<\/td>\n<\/tr>\n<tr>\n<td>\\&gt;<\/td>\n<td>Anchor &#8211; end of word<\/td>\n<\/tr>\n<tr>\n<td>\\(&#8230;\\)<\/td>\n<td>Grouping &#8211; usually used to group conditions<\/td>\n<\/tr>\n<tr>\n<td>\\n<\/td>\n<td>Contents of\u00a0nth grouping<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<table border=\"1\">\n<caption>[&#8230;] &#8211; Set Examples<\/caption>\n<tbody>\n<tr>\n<td>[A-Z]<\/td>\n<td>The SET from Capital A to Capital Z<\/td>\n<\/tr>\n<tr>\n<td>[a-z]<\/td>\n<td>The SET from lowercase a to lowercase z<\/td>\n<\/tr>\n<tr>\n<td>[0-9]<\/td>\n<td>The SET from 0 to 9 (All numerals)<\/td>\n<\/tr>\n<tr>\n<td>[.\/=+]<\/td>\n<td>The SET containing . (dot), \/ (slash), =, and +<\/td>\n<\/tr>\n<tr>\n<td>[-A-F]<\/td>\n<td>The SET from Capital A to Capital F and the dash (dashes must be specified first)<\/td>\n<\/tr>\n<tr>\n<td>[0-9 A-Z]<\/td>\n<td>The SET containing all capital letters and digits and a space<\/td>\n<\/tr>\n<tr>\n<td>[A-Z][a-zA-Z]<\/td>\n<td>In the first position, the SET from Capital A to Capital Z<br \/>\nIn the second character position, the SET containing all letters<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<table border=\"1\">\n<caption>Regular Expression Examples<\/caption>\n<tbody>\n<tr>\n<td>\/Hello\/<\/td>\n<td>Matches if the line contains the value Hello<\/td>\n<\/tr>\n<tr>\n<td>\/^TEST$\/<\/td>\n<td>Matches if the line contains TEST by itself<\/td>\n<\/tr>\n<tr>\n<td>\/^[a-zA-Z]\/<\/td>\n<td>Matches if the line starts with any letter<\/td>\n<\/tr>\n<tr>\n<td>\/^[a-z].*\/<\/td>\n<td>Matches if the first character of the line is a-z and there is at least one more of any character following it<\/td>\n<\/tr>\n<tr>\n<td>\/2134$\/<\/td>\n<td>Matches if line ends with 2134<\/td>\n<\/tr>\n<tr>\n<td>\/\\(21|35\\)\/<\/td>\n<td>Matches is the line contains 21 or 35<br \/>\nNote the use of ( ) with the pipe symbol to specify the &#8216;or&#8217; condition<\/td>\n<\/tr>\n<tr>\n<td>\/[0-9]*\/<\/td>\n<td>Matches if there are zero or more numbers in the line<\/td>\n<\/tr>\n<tr>\n<td>\/^[^#]\/<\/td>\n<td>Matches if the first character is not a # in the line<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\">Notes:<br \/>\n1. Regular expressions are case sensitive<br \/>\n2. Regular expressions are to be used where\u00a0pattern\u00a0is specified<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"count\"><\/a><\/p>\n<h2>Counts<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table>\n<tbody>\n<tr>\n<td>Nearly every command may be preceded by a number that specifies how many times it is to be performed. For example, 5dw will delete 5 words and 3fe will move the cursor forward to the 3rd occurence of the letter e. Even insertions may be repeated conveniently with thismethod, say to insert the same line 100 times.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"range\"><\/a><\/p>\n<h2>Ranges<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table>\n<tbody>\n<tr>\n<td>Ranges may precede most &#8220;colon&#8221; commands and cause them to be executed on a line or lines. For example :3,7d would delete lines 3-7. Ranges are commonly combined with the :s command to perform a replacement on several lines, as with :.,$s\/pattern\/string\/g to make a replacement from the current line to the end of the file.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>:n,m<\/td>\n<td>Range &#8211; Lines\u00a0n-m<\/td>\n<\/tr>\n<tr>\n<td>:.<\/td>\n<td>Range &#8211; Current line<\/td>\n<\/tr>\n<tr>\n<td>:$<\/td>\n<td>Range &#8211; Last line<\/td>\n<\/tr>\n<tr>\n<td>:&#8217;c<\/td>\n<td>Range &#8211; Marker\u00a0c<\/td>\n<\/tr>\n<tr>\n<td>:%<\/td>\n<td>Range &#8211; All lines in file<\/td>\n<\/tr>\n<tr>\n<td>:g\/pattern\/<\/td>\n<td>Range &#8211; All lines that contain\u00a0pattern<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"file\"><\/a><\/p>\n<h2>Files<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>:w\u00a0file<\/td>\n<td>Write to\u00a0file<\/td>\n<\/tr>\n<tr>\n<td>:r\u00a0file<\/td>\n<td>Read\u00a0file\u00a0in after line<\/td>\n<\/tr>\n<tr>\n<td>:n<\/td>\n<td>Go to next file<\/td>\n<\/tr>\n<tr>\n<td>:p<\/td>\n<td>Go to previos file<\/td>\n<\/tr>\n<tr>\n<td>:e\u00a0file<\/td>\n<td>Edit\u00a0file<\/td>\n<\/tr>\n<tr>\n<td>!!program<\/td>\n<td>Replace line with output from\u00a0program<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"other\"><\/a><\/p>\n<h2>Other<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>~<\/td>\n<td>Toggle upp and lower case<\/td>\n<\/tr>\n<tr>\n<td>J<\/td>\n<td>Join lines<\/td>\n<\/tr>\n<tr>\n<td>.<\/td>\n<td>Repeat last text-changing command<\/td>\n<\/tr>\n<tr>\n<td>u<\/td>\n<td>Undo last change<\/td>\n<\/tr>\n<tr>\n<td>U<\/td>\n<td>Undo all changes to line<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Vi Cheat Sheet &#8211; Basics &nbsp; Modes Vi has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,6],"tags":[],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-linux","category-vi"],"_links":{"self":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/comments?post=79"}],"version-history":[{"count":16,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":104,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/79\/revisions\/104"}],"wp:attachment":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/media?parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/categories?post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/tags?post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}