{"id":81,"date":"2018-07-25T13:16:36","date_gmt":"2018-07-25T09:16:36","guid":{"rendered":"http:\/\/kidds.co.za\/?p=81"},"modified":"2018-07-25T14:43:34","modified_gmt":"2018-07-25T10:43:34","slug":"vi-cheatsheet-advanced","status":"publish","type":"post","link":"https:\/\/kidds.co.za\/index.php\/2018\/07\/25\/vi-cheatsheet-advanced\/","title":{"rendered":"Vi Cheatsheet &#8211; Advanced"},"content":{"rendered":"<h1 style=\"text-align: left;\" align=\"CENTER\">Advanced Vi Cheat Sheet<\/h1>\n<p>&nbsp;<\/p>\n<hr \/>\n<p>General Notes:<\/p>\n<p>1. Before doing anything to a document, type the following command followed by a carriage return: :set showmode<\/p>\n<p>2. VI is CaSe SEnsItiVe!!! So make sure Caps Lock is OFF.<\/p>\n<hr \/>\n<p><a name=\"start\"><\/a><\/p>\n<h2>Starting and Ending VI<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table border=\"1\">\n<tbody>\n<tr>\n<td colspan=\"2\">Starting VI<\/td>\n<\/tr>\n<tr>\n<td>vi\u00a0filename<\/td>\n<td>Edits\u00a0filename<\/td>\n<\/tr>\n<tr>\n<td>vi -r\u00a0filename<\/td>\n<td>Edits last save version of\u00a0filename\u00a0after a crash<\/td>\n<\/tr>\n<tr>\n<td>vi +\u00a0n\u00a0filename<\/td>\n<td>Edits\u00a0filename\u00a0and places curser at line\u00a0n<\/td>\n<\/tr>\n<tr>\n<td>vi +\u00a0filename<\/td>\n<td>Edits\u00a0filename\u00a0and places curser on last line<\/td>\n<\/tr>\n<tr>\n<td>vi +\/string\u00a0filename<\/td>\n<td>Edits\u00a0filename\u00a0and places curser on first occurance of\u00a0string<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>vi\u00a0filename\u00a0file2\u00a0&#8230;<\/td>\n<td>Edits\u00a0filename, then edits\u00a0file2\u00a0&#8230; After the save, use :n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\">Ending VI<\/td>\n<\/tr>\n<tr>\n<td>ZZ or :wq or : x<\/td>\n<td>Saves and exits VI (no space between : and x)<\/td>\n<\/tr>\n<tr>\n<td>:w<\/td>\n<td>Saves current file but doesn&#8217;t exit<\/td>\n<\/tr>\n<tr>\n<td>:w!<\/td>\n<td>Saves current file overriding normal checks but doesn&#8217;t exit<\/td>\n<\/tr>\n<tr>\n<td>:w\u00a0file<\/td>\n<td>Saves current as\u00a0file\u00a0but doesn&#8217;t exit<\/td>\n<\/tr>\n<tr>\n<td>:w!\u00a0file<\/td>\n<td>Saves to\u00a0file\u00a0overriding normal checks but doesn&#8217;t exit<\/td>\n<\/tr>\n<tr>\n<td>:n,mw\u00a0file<\/td>\n<td>Saves lines\u00a0n\u00a0through\u00a0m\u00a0to\u00a0file<\/td>\n<\/tr>\n<tr>\n<td>:n,mw &gt;&gt;file<\/td>\n<td>Saves lines\u00a0n\u00a0through\u00a0m\u00a0to the end of\u00a0file<\/td>\n<\/tr>\n<tr>\n<td>:q<\/td>\n<td>Quits VI and may prompt if you need to save<\/td>\n<\/tr>\n<tr>\n<td>:q!<\/td>\n<td>Quits VI and without saving<\/td>\n<\/tr>\n<tr>\n<td>:e!<\/td>\n<td>Edits file discarding any unsaved changes (starts over)<\/td>\n<\/tr>\n<tr>\n<td>:we!<\/td>\n<td>Saves and continues to edit current file<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"status\"><\/a><\/p>\n<h2>Status<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>:.=<\/td>\n<td>Shows current line number<\/td>\n<\/tr>\n<tr>\n<td>:=<\/td>\n<td>Shows number of lines in file<\/td>\n<\/tr>\n<tr>\n<td>Control-G<\/td>\n<td>Shows filename, current line number, total lines in file, and % of file location<\/td>\n<\/tr>\n<tr>\n<td>l<\/td>\n<td>Displays tab (^l) backslash (\\) backspace (^H) newline ($) bell (^G) formfeed (^L^) of current line<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"mode\"><\/a><\/p>\n<h2>Modes<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table border=\"1\">\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=\"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<tr>\n<td>CTRL-v\u00a0char<\/td>\n<td>While inserting, ignores special meaning of char (e.g., for inserting characters like ESC and CTRL) until ESC is used<\/td>\n<\/tr>\n<tr>\n<td>:r\u00a0file<\/td>\n<td>Reads\u00a0file\u00a0and inserts it after current line<\/td>\n<\/tr>\n<tr>\n<td>:nr\u00a0file<\/td>\n<td>Reads\u00a0file\u00a0and inserts it after line\u00a0n<\/td>\n<\/tr>\n<tr>\n<td>CTRL-i or TAB<\/td>\n<td>While inserting, inserts one shift width<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<table border=\"1\">\n<caption>Things to do while in Insert Mode:<\/caption>\n<tbody>\n<tr>\n<td>CTRL-h or Backspace<\/td>\n<td>While inserting, deletes previous character<\/td>\n<\/tr>\n<tr>\n<td>CTRL-w<\/td>\n<td>While inserting, deletes previous word<\/td>\n<\/tr>\n<tr>\n<td>CTRL-x<\/td>\n<td>While inserting, deletes to start of inserted text<\/td>\n<\/tr>\n<tr>\n<td>CTRL-v<\/td>\n<td>Take the next character literally. (i.e. To insert a Control-H, type Control-v Control-h)<\/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>Arrow Keys<\/td>\n<td>These do work, but they may be too slow on big files. Also may have unpredictable results when arrow keys are not mapped correctly in client.<\/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>^<\/td>\n<td>Moves to the first non-blank character in the current line<\/td>\n<\/tr>\n<tr>\n<td>+ or<\/td>\n<td>Moves to the first character in the next line<\/td>\n<\/tr>\n<tr>\n<td>&#8211;<\/td>\n<td>Moves to the first non-blank character in the previous line<\/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>[[<\/td>\n<td>Move a section back<\/td>\n<\/tr>\n<tr>\n<td>]]<\/td>\n<td>Move a section forward<\/td>\n<\/tr>\n<tr>\n<td>0 or |<\/td>\n<td>Move to the begining of the line<\/td>\n<\/tr>\n<tr>\n<td>n|<\/td>\n<td>Moves to the column\u00a0n\u00a0in the current 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>nH<\/td>\n<td>Moves to\u00a0nth line from the top of the 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>nL<\/td>\n<td>Moves to\u00a0nth line from the bottom of the screen<\/td>\n<\/tr>\n<tr>\n<td>Control-d<\/td>\n<td>Move forward \u00bd screen<\/td>\n<\/tr>\n<tr>\n<td>Control-f<\/td>\n<td>Move forward one full screen<\/td>\n<\/tr>\n<tr>\n<td>Control-u<\/td>\n<td>Move backward \u00bd screen<\/td>\n<\/tr>\n<tr>\n<td>Control-b<\/td>\n<td>Move backward one full screen<\/td>\n<\/tr>\n<tr>\n<td>CTRL-e<\/td>\n<td>Moves screen up one line<\/td>\n<\/tr>\n<tr>\n<td>CTRL-y<\/td>\n<td>Moves screen down one line<\/td>\n<\/tr>\n<tr>\n<td>CTRL-u<\/td>\n<td>Moves screen up \u00bd page<\/td>\n<\/tr>\n<tr>\n<td>CTRL-d<\/td>\n<td>Moves screen down \u00bd page<\/td>\n<\/tr>\n<tr>\n<td>CTRL-b<\/td>\n<td>Moves screen up one page<\/td>\n<\/tr>\n<tr>\n<td>CTRL-f<\/td>\n<td>Moves screen down one page<\/td>\n<\/tr>\n<tr>\n<td>CTRL-I<\/td>\n<td>Redraws screen<\/td>\n<\/tr>\n<tr>\n<td>z<\/td>\n<td>z-carriage return makes the current line the top line on the page<\/td>\n<\/tr>\n<tr>\n<td>nz<\/td>\n<td>Makes the line\u00a0n\u00a0the top line on the page<\/td>\n<\/tr>\n<tr>\n<td>z.<\/td>\n<td>Makes the current line the middle line on the page<\/td>\n<\/tr>\n<tr>\n<td>nz.<\/td>\n<td>Makes the line\u00a0n\u00a0the middle line on the page<\/td>\n<\/tr>\n<tr>\n<td>z-<\/td>\n<td>Makes the current line the bottom line on the page<\/td>\n<\/tr>\n<tr>\n<td>nz-<\/td>\n<td>Makes the line\u00a0n\u00a0the bottom line on the page<\/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>nx<\/td>\n<td>Deletes n characters starting with current; omitting n deletes current character only<\/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>nX<\/td>\n<td>Deletes previous n characters; omitting n deletes previous character only<\/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>d$<\/td>\n<td>Deletes from the cursor to the end of the line<\/td>\n<\/tr>\n<tr>\n<td>dd or :d<\/td>\n<td>Delete current line<\/td>\n<\/tr>\n<tr>\n<td>ndw<\/td>\n<td>Deletes the next\u00a0n\u00a0words starting with current<\/td>\n<\/tr>\n<tr>\n<td>ndb<\/td>\n<td>Deletes the previous\u00a0n\u00a0words starting with current<\/td>\n<\/tr>\n<tr>\n<td>ndd<\/td>\n<td>Deletes\u00a0n\u00a0lines beginning with the current line<\/td>\n<\/tr>\n<tr>\n<td>:n,md<\/td>\n<td>Deletes lines\u00a0n\u00a0through\u00a0m<\/td>\n<\/tr>\n<tr>\n<td>dMotion_cmd<\/td>\n<td>Deletes everything included in the Motion Command (e.g., dG would delete from current position to the end of the file, and d4 would delete to the end of the fourth sentence).<\/td>\n<\/tr>\n<tr>\n<td>&#8220;np<\/td>\n<td>Retrieves the last\u00a0nth delete (last 9 deletes are kept in a buffer)<\/td>\n<\/tr>\n<tr>\n<td>&#8220;1pu.u.<\/td>\n<td>Scrolls through the delete buffer until the desired delete is retrieved (repeat u.)<\/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<tr>\n<td>nyy or\u00a0nY<\/td>\n<td>Places\u00a0n\u00a0lines in the buffer-copies<\/td>\n<\/tr>\n<tr>\n<td>yMotion_cmd<\/td>\n<td>Copies everything from the curser to the Motion Command (e.g., yG would copy from current position to the end of the file, and y4 would copy to the end of the fourth sentence)<\/td>\n<\/tr>\n<tr>\n<td>&#8220;(a-z)nyy or &#8220;(a-z)ndd<\/td>\n<td>Copies or cuts (deletes)\u00a0n\u00a0lines into a named buffer\u00a0a\u00a0through\u00a0z; omitting n works on current line<\/td>\n<\/tr>\n<tr>\n<td><\/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 example 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 or S<\/td>\n<td>Change the whole line until ESC is pressed<\/td>\n<\/tr>\n<tr>\n<td>xp<\/td>\n<td>Switches character at cursor with following character<\/td>\n<\/tr>\n<tr>\n<td>stext<\/td>\n<td>Substitutes text for the current character until ESC is used<\/td>\n<\/tr>\n<tr>\n<td>cwtext<\/td>\n<td>Changes current word to text until ESC is used<\/td>\n<\/tr>\n<tr>\n<td>Ctext<\/td>\n<td>Changes rest of the current line to text until ESC is used<\/td>\n<\/tr>\n<tr>\n<td>cMotion_cmd<\/td>\n<td>Changes to text from current position to Motion Command until ESC is used<\/td>\n<\/tr>\n<tr>\n<td>&lt;&lt; or &gt;&gt;<\/td>\n<td>Shifts the line left or right (respectively) by one shift width (a tab)<\/td>\n<\/tr>\n<tr>\n<td>n&lt;&lt; or\u00a0n&gt;&gt;<\/td>\n<td>Shifts\u00a0n\u00a0lines left or right (respectively) by one shift width (a tab)<\/td>\n<\/tr>\n<tr>\n<td>&lt;Motion_cmd\u00a0or &gt;Motion_cmd<\/td>\n<td>Use with Motion Command to shift multiple lines left or right<\/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 position or before the line<\/td>\n<\/tr>\n<tr>\n<td>&#8220;(a-z)p or &#8220;(a-z)P<\/td>\n<td>Pastes text from a named buffer\u00a0a\u00a0through\u00a0z\u00a0after or before the current 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<tr>\n<td>%<\/td>\n<td>Searches to beginning of balancing ( ) [ ] or { }<\/td>\n<\/tr>\n<tr>\n<td>fc<\/td>\n<td>Searches forward in current line to\u00a0char<\/td>\n<\/tr>\n<tr>\n<td>Fc<\/td>\n<td>Searches backward in current line to\u00a0char<\/td>\n<\/tr>\n<tr>\n<td>tc<\/td>\n<td>Searches forward in current line to character before char<\/td>\n<\/tr>\n<tr>\n<td>Tchar<\/td>\n<td>Searches backward in current line to character before char<\/td>\n<\/tr>\n<tr>\n<td>?str<\/td>\n<td>Finds in reverse for str<\/td>\n<\/tr>\n<tr>\n<td>:set ic<\/td>\n<td>Ignores case when searching<\/td>\n<\/tr>\n<tr>\n<td>:set noic<\/td>\n<td>Pays attention to case when searching<\/td>\n<\/tr>\n<tr>\n<td>:n,ms\/str1\/str2\/opt<\/td>\n<td>Searches from\u00a0n\u00a0to\u00a0m\u00a0for\u00a0str1; replaces\u00a0str1\u00a0to\u00a0str2; using opt-opt can be g for global change, c to confirm change (y to acknowledge,\u00a0to suppress), and p to print changed lines<\/td>\n<\/tr>\n<tr>\n<td>&amp;<\/td>\n<td>Repeats last :s command<\/td>\n<\/tr>\n<tr>\n<td>:g\/str\/cmd<\/td>\n<td>Runs\u00a0cmd\u00a0on all lines that contain\u00a0str<\/td>\n<\/tr>\n<tr>\n<td>:g\/str1\/s\/str2\/str3\/<\/td>\n<td>Finds the line containing\u00a0str1, replaces\u00a0str2\u00a0with\u00a0str3<\/td>\n<\/tr>\n<tr>\n<td>:v\/str\/cmd<\/td>\n<td>Executes\u00a0cmd\u00a0on all lines that do not match\u00a0str<\/td>\n<\/tr>\n<tr>\n<td>,<\/td>\n<td>Repeats, in reverse direction, last \/ or ? search command<\/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>\\&lt;<\/td>\n<td>Matches beginning of word<\/td>\n<\/tr>\n<tr>\n<td>\\&gt;<\/td>\n<td>Matches end of word<\/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<tr>\n<td>\\<\/td>\n<td>Escapes the meaning of the next character (e.g., \\$ allows you to search for $)<\/td>\n<\/tr>\n<tr>\n<td>\\\\<\/td>\n<td>Escapes the \\ character<\/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<tr>\n<td>[a-z]{m}<\/td>\n<td>Look for\u00a0m\u00a0occurances of the SET from lowercase a to lowercase z<\/td>\n<\/tr>\n<tr>\n<td>[a-z]{m,n}<\/td>\n<td>Look for at least\u00a0m\u00a0occurances, but no more than\u00a0n\u00a0occurances of the SET from lowercase a to lowercase z<\/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 this method, 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=\"shell\"><\/a><\/p>\n<h2>Shell Functions<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>:! cmd<\/td>\n<td>Executes shell command cmd; you can add these special characters to indicate:% name of current file# name of last file edited<\/td>\n<\/tr>\n<tr>\n<td>!! cmd<\/td>\n<td>Executes shell command cmd, places output in file starting at current line<\/td>\n<\/tr>\n<tr>\n<td>:!!<\/td>\n<td>Executes last shell command<\/td>\n<\/tr>\n<tr>\n<td>:r! cmd<\/td>\n<td>Reads and inserts output from cmd<\/td>\n<\/tr>\n<tr>\n<td>:f file<\/td>\n<td>Renames current file to file<\/td>\n<\/tr>\n<tr>\n<td>:w !cmd<\/td>\n<td>Sends currently edited file to cmd as standard input and execute cmd<\/td>\n<\/tr>\n<tr>\n<td>:cd dir<\/td>\n<td>Changes current working directory to dir<\/td>\n<\/tr>\n<tr>\n<td>:sh<\/td>\n<td>Starts a sub-shell (CTRL-d returns to editor)<\/td>\n<\/tr>\n<tr>\n<td>:so file<\/td>\n<td>Reads and executes commands in file (file is a shell script)<\/td>\n<\/tr>\n<tr>\n<td>!Motion_cmd<\/td>\n<td>Sends text from current position to Motion Command to shell command\u00a0cmd<\/td>\n<\/tr>\n<tr>\n<td>!}sort<\/td>\n<td>Sorts from current position to end of paragraph and replaces text with sorted text<\/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 previous 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=\"settings\"><\/a><\/p>\n<h2>VI Settings<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<p>&#8211;noto<\/p>\n<table border=\"1\">\n<caption>Note: Options given are default. To change them, enter type :set option to turn them on or :set nooptioni\u00a0to turn them off.To make them execute every time you open VI, create a file in your HOME directory called .exrc and type the options without the colon (:) preceding the option<\/caption>\n<tbody>\n<tr>\n<th>Set<\/th>\n<th>Default<\/th>\n<th>Description<\/th>\n<\/tr>\n<tr>\n<td>:set ai<\/td>\n<td>noai<\/td>\n<td>Turns on auto indentation<\/td>\n<\/tr>\n<tr>\n<td>:set all<\/td>\n<td>&#8212;<\/td>\n<td>Prints all options to the screen<\/td>\n<\/tr>\n<tr>\n<td>:set ap<\/td>\n<td>aw<\/td>\n<td>Prints line after d c J m :s t u commands<\/td>\n<\/tr>\n<tr>\n<td>:set aw<\/td>\n<td>noaw<\/td>\n<td>Automatic write on :n ! e# ^^ :rew ^} :tag<\/td>\n<\/tr>\n<tr>\n<td>:set bf<\/td>\n<td>nobf<\/td>\n<td>Discards control characters from input<\/td>\n<\/tr>\n<tr>\n<td>:set dir=tmp<\/td>\n<td>dir = \/tmp<\/td>\n<td>Sets\u00a0tmp\u00a0to directory or buffer file<\/td>\n<\/tr>\n<tr>\n<td>:set eb<\/td>\n<td>noed<\/td>\n<td>Precedes error messages with a bell<\/td>\n<\/tr>\n<tr>\n<td>:set ed<\/td>\n<td>noed<\/td>\n<td>Precedes error messages with a bell<\/td>\n<\/tr>\n<tr>\n<td>:set ht=<\/td>\n<td>ht = 8<\/td>\n<td>Sets terminal hardware tabs<\/td>\n<\/tr>\n<tr>\n<td>:set ic<\/td>\n<td>noic<\/td>\n<td>Ignores case when searching<\/td>\n<\/tr>\n<tr>\n<td>:set lisp<\/td>\n<td>nolisp<\/td>\n<td>Modifies brackets for Lisp compatibility.<\/td>\n<\/tr>\n<tr>\n<td>:set list<\/td>\n<td>nolist<\/td>\n<td>Shows tabs (^l) and end of line ($)<\/td>\n<\/tr>\n<tr>\n<td>:set magic<\/td>\n<td>magic<\/td>\n<td>Allows pattern matching with special characters<\/td>\n<\/tr>\n<tr>\n<td>:set mesg<\/td>\n<td>mesg<\/td>\n<td>Allows others to send messages<\/td>\n<\/tr>\n<tr>\n<td>:set nooption<\/td>\n<td><\/td>\n<td>Turns off\u00a0option<\/td>\n<\/tr>\n<tr>\n<td>:set nu<\/td>\n<td>nonu<\/td>\n<td>Shows line numbers<\/td>\n<\/tr>\n<tr>\n<td>:set opt<\/td>\n<td>opt<\/td>\n<td>Speeds output; eliminates automatic RETURN<\/td>\n<\/tr>\n<tr>\n<td>:set para=<\/td>\n<td>para = LIlPLPPPQPbpP<\/td>\n<td>macro names that start paragraphs for { and } operators<\/td>\n<\/tr>\n<tr>\n<td>:set prompt<\/td>\n<td>prompt<\/td>\n<td>Prompts for command input with :<\/td>\n<\/tr>\n<tr>\n<td>:set re<\/td>\n<td>nore<\/td>\n<td>Simulates smart terminal on dumb terminal<\/td>\n<\/tr>\n<tr>\n<td>:set remap<\/td>\n<td>remap<\/td>\n<td>Accept macros within macros<\/td>\n<\/tr>\n<tr>\n<td>:set report<\/td>\n<td>noreport<\/td>\n<td>Indicates largest size of changes reported on status line<\/td>\n<\/tr>\n<tr>\n<td>:set ro<\/td>\n<td>noro<\/td>\n<td>Changes file type to &#8220;read only&#8221;<\/td>\n<\/tr>\n<tr>\n<td>:set scroll=n<\/td>\n<td>scroll = 11<\/td>\n<td>set n lines for CTRL-d and z<\/td>\n<\/tr>\n<tr>\n<td>:set sh=shell_path<\/td>\n<td>sh = \/bin\/sh<\/td>\n<td>set shell escape (default is \/bin\/sh) to\u00a0shell_path<\/td>\n<\/tr>\n<tr>\n<td>:set showmode<\/td>\n<td>nosm<\/td>\n<td>Indicates input or replace mode at bottom<\/td>\n<\/tr>\n<tr>\n<td>:set slow<\/td>\n<td>slow<\/td>\n<td>Pospone display updates during inserts<\/td>\n<\/tr>\n<tr>\n<td>:set sm<\/td>\n<td>nosm<\/td>\n<td>Show matching { or ( as ) or } is typed<\/td>\n<\/tr>\n<tr>\n<td>:set sw=n<\/td>\n<td>sw = 8<\/td>\n<td>Sets shift width to\u00a0n\u00a0characters<\/td>\n<\/tr>\n<tr>\n<td>:set tags=x<\/td>\n<td>tags = \/usr\/lib\/tags<\/td>\n<td>Path for files checked for tags (current directory included in default)<\/td>\n<\/tr>\n<tr>\n<td>:set term<\/td>\n<td>$TERM<\/td>\n<td>Prints terminal type<\/td>\n<\/tr>\n<tr>\n<td>:set terse<\/td>\n<td>noterse<\/td>\n<td>Shorten messages with terse<\/td>\n<\/tr>\n<tr>\n<td>:set timeout<\/td>\n<td><\/td>\n<td>Eliminates one-second time limit for macros<\/td>\n<\/tr>\n<tr>\n<td>:set tl=n<\/td>\n<td>tl = 0<\/td>\n<td>Sets significance of tags beyond\u00a0n\u00a0characters (0 means all)<\/td>\n<\/tr>\n<tr>\n<td>:set ts=n<\/td>\n<td>ts = 8<\/td>\n<td>Sets tab stops to\u00a0n\u00a0for text input<\/td>\n<\/tr>\n<tr>\n<td>:set wa<\/td>\n<td>nowa<\/td>\n<td>Inhibits normal checks before write commands<\/td>\n<\/tr>\n<tr>\n<td>:set warn<\/td>\n<td>warn<\/td>\n<td>Warns &#8220;no write since last change&#8221;<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>:set window=n<\/td>\n<td>window = n<\/td>\n<td>Sets number of lines in a text window to\u00a0n<\/td>\n<\/tr>\n<tr>\n<td>:set wm=n<\/td>\n<td>wm = 0<\/td>\n<td>Sets automatic wraparound\u00a0n\u00a0spaces from right margin.<\/td>\n<\/tr>\n<tr>\n<td>:set ws<\/td>\n<td>ws<\/td>\n<td>Sets automatic wraparound\u00a0n\u00a0spaces from right margin.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"mapping\"><\/a><\/p>\n<h2>Key Mapping<\/h2>\n<hr align=\"left\" width=\"75%\" \/>\n<table border=\"1\">\n<caption>NOTE: Map allows you to define strings of VI commands. If you create a file called &#8220;.exrc&#8221; in your home directory, any map or set command you place inside this file will be executed every time you run VI. To imbed control characters like ESC in the macro, you need to precede them with CTRL-v. If you need to include quotes (&#8220;), precede them with a \\ (backslash). Unused keys in vi are: K V g q v * = and the function keys.<br \/>\nExample\u00a0(The actual VI commands are in blue): :map v\u00a0\/I CTRL-v\u00a0ESC\u00a0dwiYou CTRL-v\u00a0ESC\u00a0ESC<br \/>\nDescription: When v is pressed, search for &#8220;I&#8221; (\/I ESC), delete word (dw), and insert &#8220;You&#8221; (iYou ESC). CTRL-v allows ESC to be inserted<\/caption>\n<tbody>\n<tr>\n<td>:map\u00a0key\u00a0cmd_seq<\/td>\n<td>Defines\u00a0key\u00a0to run\u00a0cmd_seq\u00a0when pressed<\/td>\n<\/tr>\n<tr>\n<td>:map<\/td>\n<td>Displays all created macros on status line<\/td>\n<\/tr>\n<tr>\n<td>:unmap key<\/td>\n<td>Removes macro definition for key<\/td>\n<\/tr>\n<tr>\n<td>:ab\u00a0str\u00a0string<\/td>\n<td>When\u00a0str\u00a0is input, replaces it with\u00a0string<\/td>\n<\/tr>\n<tr>\n<td>:ab<\/td>\n<td>Displays all abbreviations<\/td>\n<\/tr>\n<tr>\n<td>:una\u00a0str<\/td>\n<td>Unabbreviates\u00a0str<\/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 upper and lower case<\/td>\n<\/tr>\n<tr>\n<td>J<\/td>\n<td>Join lines<\/td>\n<\/tr>\n<tr>\n<td>nJ<\/td>\n<td>Joins the next\u00a0n\u00a0lines together; omitting n joins the beginning of the next line to the end of the current line<\/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 (Note: u in combination with . can allow multiple levels of undo in some versions)<\/td>\n<\/tr>\n<tr>\n<td>U<\/td>\n<td>Undo all changes to line<\/td>\n<\/tr>\n<tr>\n<td>;<\/td>\n<td>Repeats last f F t or T search command<\/td>\n<\/tr>\n<tr>\n<td>:N or :E<\/td>\n<td>You can open up a new split-screen window in (n)vi and then use ^w to switch between the two.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Advanced Vi Cheat Sheet &nbsp; General Notes: 1. Before doing anything to a document, type the following command followed by a carriage return: :set showmode 2. VI is CaSe SEnsItiVe!!! So make sure Caps Lock is OFF. Starting and Ending VI Starting VI vi\u00a0filename Edits\u00a0filename vi -r\u00a0filename Edits last save version of\u00a0filename\u00a0after a crash vi [&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-81","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\/81","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=81"}],"version-history":[{"count":9,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":105,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/81\/revisions\/105"}],"wp:attachment":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/media?parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/categories?post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/tags?post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}