{"id":259,"date":"2015-04-26T18:17:08","date_gmt":"2015-04-26T18:17:08","guid":{"rendered":"https:\/\/notiz.comanet.xyz\/?p=259"},"modified":"2019-03-03T19:42:29","modified_gmt":"2019-03-03T18:42:29","slug":"vi-editor-manual","status":"publish","type":"post","link":"https:\/\/notiz.comanet.xyz\/?p=259","title":{"rendered":"vi Editor Manual"},"content":{"rendered":"<section class=\"container content\" id=\"main-content\">\n<article>\n<h1> \t<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-258\" alt=\"\" src=\"https:\/\/notiz.comanet.xyz\/wp-content\/uploads\/2015\/04\/index.jpg\" style=\"width: 247px; height: 204px;\" width=\"247\" height=\"204\" \/><\/h1>\n<h1> \tLinux and Unix vi command<\/h1>\n<h2> \tQuick links<\/h2>\n<p class=\"tabb\"> \t<a href=\"http:\/\/www.computerhope.com\/unix\/uvi.htm#01\">About Vi<\/a><br \/> \t<a href=\"http:\/\/www.computerhope.com\/unix\/uvi.htm#02\">Syntax<\/a><br \/> \t<a href=\"http:\/\/www.computerhope.com\/unix\/uvi.htm#Using-Vi\">Using Vi<\/a><br \/> \t<a href=\"http:\/\/www.computerhope.com\/unix\/uvi.htm#Moving-Around-In-Vi\">Moving Around in Vi<\/a><br \/> \t<a href=\"http:\/\/www.computerhope.com\/unix\/uvi.htm#Making-Simple-Changes\">Making Simple Changes<\/a><br \/> \t<a href=\"http:\/\/www.computerhope.com\/unix\/uvi.htm#Rearranging-And-Duplicating-Text\">Rearranging and Duplicating Text<\/a><br \/> \t<a href=\"http:\/\/www.computerhope.com\/unix\/uvi.htm#High-Level-Commands\">High Level Commands<\/a><br \/> \t<a href=\"http:\/\/www.computerhope.com\/unix\/uvi.htm#Special-Topics\">Special Topics<\/a><br \/> \t<a href=\"http:\/\/www.computerhope.com\/unix\/uvi.htm#Technical-Details\">Technical Details<\/a><br \/> \t<a href=\"http:\/\/www.computerhope.com\/unix\/uvi.htm#Quick-Reference\">Quick Reference<\/a><br \/> \t<a href=\"http:\/\/www.computerhope.com\/unix\/uvi.htm#03\">Examples<\/a><br \/> \t<a href=\"http:\/\/www.computerhope.com\/unix\/uvi.htm#04\">Related commands<\/a><br \/> \t<a href=\"http:\/\/www.computerhope.com\/unix.htm\">Linux and Unix main page<\/a><\/p>\n<h2> \t<a name=\"01\"><\/a>About vi<\/h2>\n<p class=\"tab intro\"> \tOriginally developed by <a href=\"http:\/\/www.computerhope.com\/people\/william_joy.htm\">William Joy<\/a> in the late 1970s, <b>vi<\/b> (pronounced &quot;vee-eye&quot;) is a <b>vi<\/b>sual text editor.<\/p>\n<h2> \t<a name=\"02\"><\/a>Syntax<\/h2>\n<pre class=\"tcy\" style=\"line-height:1.4\">vi [ -| -s ] [-l] [-L] [-R] [ -r [ <i>filename<\/i> ] ] [-S] [-t <i>tag<\/i>] [-v] [-V]    [-x] [-w] [-n ] [-C] [+<i>command<\/i> | -c <i>command<\/i> ] <i>filename<\/i><\/pre>\n<h2> \tDescription<\/h2>\n<p class=\"tab\"> \t<b>vi<\/b> is actaully the command which starts the visual mode of <b><a href=\"http:\/\/www.computerhope.com\/unix\/uex.htm\">ex<\/a><\/b>, the landmark editing program developed by Joy. As <b>ex<\/b> gained popularity, Joy noticed that most users were exclusively using its visual mode, so to make things more convenient for his users, he added a link to <b>ex<\/b> which started it in visual mode automatically. Today <b>vi<\/b> is the most popular text editor among <a href=\"http:\/\/www.computerhope.com\/jargon\/l\/linux.htm\">Linux<\/a> users.<\/p>\n<p> \tA more feature-rich implementation of <b>vi<\/b> named <b>vim<\/b> (which stands for &quot;vi improved&quot;) is also available. For more information, please see our <a href=\"http:\/\/www.computerhope.com\/unix\/vim.htm\"><b>vim<\/b> documentation<\/a>.<\/p>\n<h2> \tOptions<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td width=\"250\"> \t\t\t\t<b>&#8211;<\/b> | <b>-s<\/b><\/td>\n<td> \t\t\t\tSuppress all interactive user feedback. This is useful when processing editor <a href=\"http:\/\/www.computerhope.com\/jargon\/s\/script.htm\">scripts<\/a>.<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>-l<\/b><\/td>\n<td> \t\t\t\tSet up for editing <a href=\"http:\/\/www.computerhope.com\/jargon\/l\/lisp.htm\">LISP<\/a> programs.<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>-r<\/b><\/td>\n<td> \t\t\t\tList the name of all files saved as the result of an editor or system crash.<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>-r<\/b> <i>filename<\/i><\/td>\n<td> \t\t\t\tEdit <i>filename<\/i> after an editor or system crash. (Recovers the version of <i>filename<\/i> that was in the buffer when the crash occurred.)<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>-L<\/b><\/td>\n<td> \t\t\t\tSame as <b>-r<\/b><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>-R<\/b><\/td>\n<td> \t\t\t\t<a href=\"http:\/\/www.computerhope.com\/jargon\/r\/readonly.htm\">Readonly<\/a> mode; the readonly flag is set, preventing accidental overwriting of the file.<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>-S<\/b><\/td>\n<td> \t\t\t\tThis option is used in conjunction with the <b>-t<\/b> tag option to tell <b>vi<\/b> that the tags file may not be sorted and that, if the binary search (which relies on a sorted tags file) for <i>tag<\/i> fails to find it, the much slower linear search should also be done. Since the linear search is slow, users of large tags files should ensure that the tags files are sorted rather than use this flag. Creation of tags files normally produces sorted tags files. See <b><a href=\"http:\/\/www.computerhope.com\/unix\/uctags.htm\">ctags<\/a><\/b> for more information on tags files.<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>-t<\/b> <i>tag<\/i><\/td>\n<td> \t\t\t\tEdit the file containing the tag <i>tag<\/i>, and position the editor at its definition.<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>-V<\/b><\/td>\n<td> \t\t\t\t<a href=\"http:\/\/www.computerhope.com\/jargon\/v\/verbose.htm\">Verbose<\/a> mode. When <b>ex<\/b> commands are read by means of <a href=\"http:\/\/www.computerhope.com\/jargon\/s\/stdin.htm\">standard input<\/a>, the input will be echoed to standard error. This may be useful when processing <b>ex<\/b> commands within shell scripts.<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>-x<\/b><\/td>\n<td> \t\t\t\t<a href=\"http:\/\/www.computerhope.com\/jargon\/e\/encrypt.htm\">Encryption<\/a> option; when used, <b>vi<\/b> simulates the <b>X<\/b> command of <b>ex<\/b> and prompts the user for a key. This key is used to <a href=\"http:\/\/www.computerhope.com\/jargon\/e\/encrypt.htm\">encrypt<\/a> and <a href=\"http:\/\/www.computerhope.com\/jargon\/d\/decrypti.htm\">decrypt<\/a> text using the <a href=\"http:\/\/www.computerhope.com\/jargon\/a\/algorith.htm\">algorithm<\/a> of the <a href=\"http:\/\/www.computerhope.com\/unix\/crypt.htm\">crypt<\/a> command. The <b>X<\/b> command makes an educated guess to determine whether text read in is encrypted or not. The temporary <a href=\"http:\/\/www.computerhope.com\/jargon\/b\/buffer.htm\">buffer<\/a> file is encrypted also, using a transformed version of the key typed in for the <b>-x<\/b> option. If an empty encryption key is entered (that is, if the return key is pressed right after the <a href=\"http:\/\/www.computerhope.com\/jargon\/p\/prompt.htm\">prompt<\/a>), the file will not be encrypted. This is a good way to decrypt a file erroneously encrypted with a mistyped encryption key, such as a backspace or undo key.<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>-w<\/b><i>n<\/i><\/td>\n<td> \t\t\t\tSet the default window size to <i>n<\/i>. This is useful when using the editor over a slow speed line.<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>-C<\/b><\/td>\n<td> \t\t\t\tEncryption option; same as the <b>-x<\/b> option, except that <b>vi<\/b> simulates the C command of <b>ex<\/b>. The C command is like the <b>X<\/b> command of <b>ex<\/b>, except that all text read in is assumed to have been encrypted.<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td style=\"line-height:1.4\"> \t\t\t\t<b>+<\/b><i>command<\/i> | <b>-c<\/b> <i>command<\/i><\/td>\n<td> \t\t\t\tBegin editing by executing the specified editor command (usually a search or positioning command).<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<i>filename<\/i><\/td>\n<td> \t\t\t\tThe file to be edited.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1> \t<a name=\"Using-Vi\"><\/a>Using Vi<\/h1>\n<p class=\"tab\"> \t<b>vi<\/b> is an interactive text editor which is <i>display-oriented<\/i>: the screen of your <a href=\"http:\/\/www.computerhope.com\/jargon\/t\/terminal.htm\">terminal<\/a> acts as a window into the file you are editing. Changes you make to the file are reflected in what you see.<\/p>\n<p> \tUsing <b>vi<\/b> you can insert text anywhere in the file very easily. Most of the <b>vi<\/b> commands move the <a href=\"http:\/\/www.computerhope.com\/jargon\/c\/cursor.htm\">cursor<\/a> around in the file. You can move the cursor forward and backward in units of characters, words, sentences, and paragraphs. Some of the operators, like <b>d<\/b> for delete and <b>c<\/b> for change, can be combined with the motion commands to make them operate on entire words, paragraphs, etc., in a natural way.<\/p>\n<h2> \tEditing A File<\/h2>\n<p class=\"tab\"> \tThe most common way to start a <b>vi<\/b> session is to tell it which file to edit. To edit a file named <b>filename<\/b>, use the command:<\/p>\n<pre class=\"tab tcy\">vi filename<\/pre>\n<p class=\"tab\"> \tThe screen will clear and the text of your file will appear on the screen. If <b>filename<\/b> doesn&#39;t exist yet, <b>vi<\/b> will start you in a new file, and when you tell it to save your work, it will use the <b>filename<\/b> that you specified.<\/p>\n<h2> \tThe Editor&#39;s Copy: The &quot;Buffer&quot;<\/h2>\n<p class=\"tab\"> \tThe editor does not directly modify the file you are editing. Instead, it makes a copy of this file in memory called the <i>buffer<\/i>. You do not actually affect the contents of the file until you write the changes you&#39;ve made back into the original file.<\/p>\n<h2> \tArrow Keys<\/h2>\n<p class=\"tab\"> \tOn most terminals, you can use the arrow keys to move the cursor around. Left and right moves the cursor left or right one character, and up and down move the cursor up or down one line. The other way to move the cursor is with the <b>h<\/b>, <b>j<\/b>, <b>k<\/b>, and <b>l<\/b> keys:<\/p>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>h<\/b><\/td>\n<td> \t\t\t\tleft<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>j<\/b><\/td>\n<td> \t\t\t\tdown<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>k<\/b><\/td>\n<td> \t\t\t\tup<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>l<\/b><\/td>\n<td> \t\t\t\tright<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"tab\"> \tA bit of historical trivia: the <b>hjkl<\/b> keys are used because the original computer system Bill Joy developed with did not have separate arrow keys. Instead, the keyboard used <b>hjkl<\/b> keys as the arrow keys.<\/p>\n<p> \tHardcore <b>vi<\/b> users will tell you that the <b>hjkl<\/b> keys are the only &quot;true&quot; way to move the cursor because you can keep your hands in the typing position, but you should use whatever you&#39;re comfortable with.<\/p>\n<h2> \tSpecial Keys: Esc, Return, and Delete<\/h2>\n<p class=\"tab\"> \tThe Escape key is very important in <b>vi<\/b>: it is used to cancel any command you&#39;ve started typing, and to return to command-mode after you&#39;ve been inserting or adding text. Escape is a safe key to hit if you&#39;ve lost track of what mode you&#39;re in or what you&#39;re doing. You can hit it several times to return to command mode and cancel anything that you&#39;ve been doing.<\/p>\n<p> \tThe Return (or &quot;Enter&quot;) key is used to complete certain commands and execute them.<\/p>\n<p> \tThe Delete key is another &quot;safe&quot; key to press. It interrupts anything that the editor has been doing and brings you back to the default state of the editor, sometimes also called the &quot;quiescent&quot; state.<\/p>\n<h2> \tExiting vi<\/h2>\n<p class=\"tab\"> \tThe command <b>ZZ<\/b> will write the contents of the buffer into the file you are editing, and quit <b>vi<\/b>.<\/p>\n<p> \tIf there are no changes to be saved, you can also quit the editor with the command <b>:q<\/b>. If you have made changes that haven&#39;t been saved yet, the editor won&#39;t let you exit this way.<\/p>\n<p> \tIf you want to quit and discard the changes you&#39;ve made, you can tell the editor you&#39;re sure you know what you&#39;re doing by quitting with the command <b>:q!<\/b>. This will exit <b>vi<\/b> immediately, and any unsaved changes will be lost.<\/p>\n<h1> \t<a name=\"Moving-Around-In-Vi\"><\/a>Moving Around In Your File<\/h1>\n<h2> \tScrolling And Paging<\/h2>\n<p class=\"tab\"> \tThe editor has several commands for moving around within your file. One of the most useful of these is <b>Control-D<\/b> (also represented as <b>^D<\/b>). This command &quot;scrolls&quot; down in the file (the <b>D<\/b> stands for &quot;down&quot;). <b>^U<\/b> (&quot;up&quot;) is similar: it scrolls up one page in the file. Both of these commands will also move the cursor to the new location.<\/p>\n<p> \tIf you just want to see more of the file, but leave the cursor where it is, you can use <b>^E<\/b> to &quot;expose&quot; one more line at the bottom of the screen. <b>^Y<\/b> (which doesn&#39;t stand for anything, but it&#39;s next to the <b>U<\/b> on the keyboard) exposes one line at the top of the screen.<\/p>\n<p> \tThere are other ways to move around in the file. The keys <b>^F<\/b> and <b>^B<\/b> move forward and backward one page (this is called &quot;paging&quot;), keeping a couple of lines of continuity between screens so that it is possible to read through a file using these rather than <b>^D<\/b> and <b>^U<\/b> if you wish.<\/p>\n<p> \tNotice the difference between &quot;scrolling&quot; (<b>^U<\/b>, <b>^D<\/b>) and &quot;paging&quot; (<b>^B<\/b>, <b>^F<\/b>). Scrolling leaves more context, but paging only leaves you a couple of lines. It&#39;s up to you which one is easier for moving around and reading your file.<\/p>\n<h2> \tSearching<\/h2>\n<p class=\"tab\"> \tAnother way to position yourself in the file is by giving the editor a <a href=\"http:\/\/www.computerhope.com\/jargon\/s\/string.htm\">string<\/a> to search for. If you type &quot;<b>\/<\/b>&quot; followed by a string of characters and press Enter, the editor will search for the next occurrence of this string in your file, and place the cursor there. Pressing <b>n<\/b> will go to the next occurrence after that.<\/p>\n<p> \tIf instead of forward, you want to search backward for a string, use <b>?<\/b> instead of <b>\/<\/b>. In a <b>?<\/b> string search, pressing <b>n<\/b> will take you to successive occurrences in the same (backward) direction.<\/p>\n<p> \tIf the search string you give the editor is not present in the file, the editor will print a message letting you know it couldn&#39;t find it, and your cursor will not be moved.<\/p>\n<p> \tIf you want your search string only to match if it&#39;s at the beginning of a line, you should begin the search string with a carat (&quot;<b>^<\/b>&quot;). To match only at the end of a line, end the search string with a dollar sign (&quot;<b>$<\/b>&quot;). So using the command<\/p>\n<pre class=\"tab tcy\">\/^mystring<\/pre>\n<p class=\"tab\"> \twill only find a match if &quot;<b>mystring<\/b>&quot; is at the very begining of a line. Similarly, the command<\/p>\n<pre class=\"tab tcy\">\/mystring$<\/pre>\n<p class=\"tab\"> \twill only match any occurrences of &quot;<b>mystring<\/b>&quot; that are at the very end of a line.<\/p>\n<h2> \t&quot;Goto&quot;-ing<\/h2>\n<p class=\"tab\"> \tThe command <b>G<\/b>, when preceded by a number, will &quot;goto&quot; a line: it will go to that line number and position the cursor there. If you simply use <b>G<\/b> with no number, it will move the cursor to the last line of the file.<\/p>\n<p> \tSo, using the command<\/p>\n<pre class=\"tab tcy\">1G<\/pre>\n<p class=\"tab\"> \tWill move your cursor to the first line in the file;<\/p>\n<pre class=\"tab tcy\">30G<\/pre>\n<p class=\"tab\"> \tWill move your cursor to line 30, and<\/p>\n<pre class=\"tab tcy\">G<\/pre>\n<p class=\"tab\"> \tWill move your cursor to the last line, whatever number that may be.<\/p>\n<h2> \tFinding Out Where You Are In The File<\/h2>\n<p class=\"tab\"> \tYou can find out where you&#39;re at in the file by pressing <b>^G<\/b>. This sill show you the name of the file you are editing, the number of the current line, the number of lines in the buffer, and the percentage of the way through the buffer your cursor is currently at.<\/p>\n<h2> \tGetting Back To Where You Just Were<\/h2>\n<p class=\"tab\"> \tAny time you move the cursor in any of these ways, you can move the cursor back to where it just was by typing <b>&#8220;<\/b> (two <a href=\"http:\/\/www.computerhope.com\/jargon\/b\/backquot.htm\">back quotes<\/a>). So, if you type<\/p>\n<pre class=\"tab tcy\">G<\/pre>\n<p class=\"tab\"> \tto move to the end of the file, but then you realize you need to get back to where you were (whether you remember where that is or not), you can type<\/p>\n<pre class=\"tab tcy\">``<\/pre>\n<p class=\"tab\"> \tTo get back to your original location. This also works after performing a search. Remember this command, because it&#39;s very useful!<\/p>\n<h2> \tLines Past The End Of Your File<\/h2>\n<p class=\"tab\"> \tIf you&#39;re near the end of your file, and the last line is not at the bottom of the screen, <b>vi<\/b> will print a <a href=\"http:\/\/www.computerhope.com\/jargon\/t\/tilde.htm\">tilde<\/a> (&quot;<b>~<\/b>&quot;) on any lines after the end of your actual file. This indicates that the last line of your file is on the screen; that is, any lines showing &quot;<b>~<\/b>&quot; are past the end of your file. You&#39;ll notice this, for instance, when you start editing a new file: every line will begin with a tilde.<\/p>\n<h2> \tMoving Around On The Screen<\/h2>\n<p class=\"tab\"> \tAs we&#39;ve already mentioned, you can use the arrow keys or <b>h<\/b>, <b>j<\/b>, <b>k<\/b>, and <b>l<\/b> to move the cursor left and right one cursor, or up and down one line.<\/p>\n<p> \tYou can also use <b>+<\/b> to move to the next line or <b>&#8211;<\/b> to move to the previous line. This is similar to using <b>up<\/b> and <b>down<\/b> (or <b>j<\/b> and <b>k<\/b>), except that your cursor will automatically be placed at the first non-<a href=\"http:\/\/www.computerhope.com\/jargon\/w\/whitspac.htm\">whitespace<\/a> character on the line.<\/p>\n<p> \tAny of these keys, if they would take you before the first line on the screen or after the last line, will scroll the display one line in the correct direction. Pressing the <b>Return<\/b> key is the same as pressing <b>+<\/b>. You can also position the cursor at the top, middle, or bottom of the currently-displayed screen of text:<\/p>\n<p> \t<b>H<\/b> will take you to the top (&quot;home&quot;) line on the screen. Preceding <b>H<\/b> with a number will take you to the home line plus that number of lines. For instance, <b>3H<\/b> will move your cursor to the third line of text displayed on the screen.<\/p>\n<p> \t<b>M<\/b> is a similar command: it moves your cursor to the middle of the screen.<\/p>\n<p> \t<b>L<\/b> moves your cursor to the last line of the screen. If you precede it with a number, it will move your cursor to that number of lines before the last line displayed. So <b>5L<\/b> will move your cursor to the fifth-to-last line currently displayed.<\/p>\n<h2> \tMoving Within A Line<\/h2>\n<p class=\"tab\"> \t<b>w<\/b> will advance the cursor to the next word on the line, and <b>b<\/b> will back up the cursor to the previous word.<\/p>\n<p> \t<b>e<\/b> advances you to the end of the current word rather than the beginning of the next word.<\/p>\n<p> \tIf words are punctuated, for instance with an apostrophe or a comma, <b>w<\/b> and <b>b<\/b> will stop at the punctuation. If you use <b>W<\/b> and <b>B<\/b> instead, they will move the cursor while ignoring punctuation.<\/p>\n<p> \tThese commands all wrap at the end (or beginning) of a line, moving to the previous or next line if their search for the next or previous word goes that far.<\/p>\n<h2> \tSummary: Movement Keys<\/h2>\n<p class=\"tab\"> \tHere&#39;s a recap of the movement keys we just discussed, and a few extras.<\/p>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\tSPACE BAR<\/td>\n<td> \t\t\t\tadvance the cursor one position<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^B<\/b><\/td>\n<td> \t\t\t\tpage backward<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^D<\/b><\/td>\n<td> \t\t\t\tscroll down<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^E<\/b><\/td>\n<td> \t\t\t\texpose a line at the bottom of the screen<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^F<\/b><\/td>\n<td> \t\t\t\tpage forward<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^G<\/b><\/td>\n<td> \t\t\t\tPositional status check<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^N<\/b><\/td>\n<td> \t\t\t\tnext line, same column<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^P<\/b><\/td>\n<td> \t\t\t\tprevious line, same column<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^U<\/b><\/td>\n<td> \t\t\t\tscroll up<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^Y<\/b><\/td>\n<td> \t\t\t\texpose a line at the top of the screen<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>+<\/b><\/td>\n<td> \t\t\t\tnext line, at the first non-whitespace character<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>&#8211;<\/b><\/td>\n<td> \t\t\t\tprevious line, at the first non-whitespace character<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>\/<\/b><i>string<\/i><\/td>\n<td> \t\t\t\tScan forward for <i>string<\/i>. If no <i>string<\/i> is specified, scans for the last <i>string<\/i> scanned for.<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>?<\/b><\/td>\n<td> \t\t\t\tScan backwards for <i>string<\/i>. If no <i>string<\/i> is specified, scans for the last <i>string<\/i> scanned for.<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>B<\/b><\/td>\n<td> \t\t\t\tbackwards one word, ignoring punctuation<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<i>linenumber<\/i><b>G<\/b><\/td>\n<td> \t\t\t\tGo to specified <i>linenumber<\/i> (an <a href=\"http:\/\/www.computerhope.com\/jargon\/i\/integer.htm\">integer<\/a>). Defaults to the last line.<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>H<\/b><\/td>\n<td> \t\t\t\tmove cursor to first line of screen<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>M<\/b><\/td>\n<td> \t\t\t\tmiddle line of screen<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>L<\/b><\/td>\n<td> \t\t\t\tlast line of screen<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>W<\/b><\/td>\n<td> \t\t\t\tforward a word, ignoring punctuation<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>b<\/b><\/td>\n<td> \t\t\t\tbackwards a word<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>e<\/b><\/td>\n<td> \t\t\t\tend of current word<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>n<\/b><\/td>\n<td> \t\t\t\tnext instance of <b>\/<\/b> or <b>?<\/b> search pattern<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>w<\/b><\/td>\n<td> \t\t\t\tnext word<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1> \t<a name=\"Making-Simple-Changes\"><\/a>Making Simple Changes<\/h1>\n<p class=\"tab\"> \tThe most basic command for making changes to your file is the <i>i<\/i> (insert) command. After you type <i>i<\/i>, everything you type until you hit <b>ESC<\/b> is inserted at your cursor position into the buffer.<\/p>\n<p> \tThe companion to the <i>i<\/i> command is the <b>a<\/b> (&quot;append&quot;) command. This works exactly like <i>i<\/i>, except it starts inserting the text <i>after<\/i> the cursor location, not <i>at<\/i> the cursor location.<\/p>\n<p> \tSometimes, you want to start editing on a new line right after the line your cursor is at. To do this, use the <i>o<\/i> command. To start a new line <i>before<\/i> the line your cursor is at, use the <b>O<\/b> command. Just like with <i>i<\/i> and <i>a<\/i>, any text you type will be inserted into the buffer until you press <b>ESC<\/b>.<\/p>\n<p> \tWhile you are inserting text with any of these commands, you can use <b>^W<\/b> to erase a whole word and leave your cursor one space after the previous word.<br \/> \tOne thing to note is that when you backspace, you will not erase any characters that you haven&#39;t inserted. Also, you can&#39;t backspace to the previous line; backspacing will stop when you get to the beginning of the current line.<\/p>\n<h2> \tMaking Small Corrections<\/h2>\n<p class=\"tab\"> \tIt&#39;s easy to make small corrections in <b>vi<\/b>. If you need to remove a character that shouldn&#39;t be there, move the cursor over it and press <b>x<\/b> to delete it. You can also supply a number before pressing <b>x<\/b>, and it will delete that many characters. So if you have the word &quot;<b>discovery<\/b>&quot;, and you move the cursor over the <b>v<\/b> and type<\/p>\n<pre class=\"tab tcy\">4x <\/pre>\n<p class=\"tab\"> \t&#8230;you will be left with the word &quot;<b>disco<\/b>&quot;.<\/p>\n<p> \tIf you want to replace a single character with another character, move the cursor over it and press <b>r<\/b> and then the character that should replace it. So, if you type &quot;<b>mistoke<\/b>&quot;, and move the cursor over the &quot;<b>o<\/b>&quot; and type<\/p>\n<pre class=\"tab tcy\">ra<\/pre>\n<p class=\"tab\"> \t&#8230;the <b>o<\/b> will be replaced with an <b>a<\/b>, leaving you with the word &quot;<b>mistake<\/b>.&quot;<\/p>\n<p> \tThe <b>R<\/b> command is similar, but you can use it to replace more than one character; if you press <b>R<\/b> and start typing, every character you type will replace every character that was already there. So, if you have the word &quot;<b>mistake<\/b>&quot;, and you move the cursor over the letter <b>t<\/b> and type<\/p>\n<pre class=\"tab tcy\">Rsile<\/pre>\n<p class=\"tab\"> \t&#8230;you will see that the word &quot;<b>mistake<\/b>&quot; has turned into the word &quot;<b>missile<\/b>&quot;. You might also notice that if you backspace in this mode, your original text will be restored, letter by letter. When you&#39;re done, press <b>ESC<\/b> to stop replacing characters.<\/p>\n<h2> \tOperators<\/h2>\n<p class=\"tab\"> \tThe command <b>d<\/b> acts as a <i>delete operator<\/i>: presing <b>d<\/b> and then a movement key will delete wherever the cursor would have moved. For instance, typing <b>dw<\/b> will delete the next word, and typing <b>db<\/b> will delete backwards to the previous word. Typing <b>d<\/b>SPACE will delete one character; this is the same as typing <b>x<\/b>.<\/p>\n<p> \tAnother useful operator is <b>c<\/b>, which stands for <i>change<\/i>. The command <b>cw<\/b> will change a single word: it will delete everything to the end of a word, and place you into insert mode to type the text that should replace it.<\/p>\n<h2> \tRepeating A Change<\/h2>\n<p class=\"tab\"> \tAny time you make a change with a command, you can type &quot;<b>.<\/b>&quot; to repeat the change. So if you delete a word with <b>dw<\/b>, typing <b>.<\/b> will delete the next word as well. You can repeat this over and over by typing <b>.<\/b> several times, like an ellipsis (&quot;<b>&#8230;<\/b>&quot;).<\/p>\n<h2> \tOperating On Lines<\/h2>\n<p class=\"tab\"> \tTyping <b>dd<\/b> will delete an entire line.<\/p>\n<p> \tTyping <b>cc<\/b> will change an entire line, deleting it and placing you in insert mode.<\/p>\n<p> \tYou can delete or change more than one line at a time by preceding <b>dd<\/b> or <b>cc<\/b> with a number. For instance, <b>5dd<\/b> will delete 5 lines. You can also give a command like <b>dL<\/b> which will delete every line from the cursor up to and including the last line on the screen, or <b>d3L<\/b> which will delete every line from the cursor to the third-to-last line. When you make big changes like this, especially if you make changes that go beyond what you can see in one screen, the editor will give you a message telling you what&#39;s been done.<\/p>\n<h2> \tUndoing<\/h2>\n<p class=\"tab\"> \tTo undo the last change, type <b>u<\/b>. To re-do (to undo an undo), type <b>u<\/b> again.<\/p>\n<p> \tUnlike <a href=\"http:\/\/www.computerhope.com\/jargon\/v\/vim.htm\"><b>vim<\/b><\/a>, <b>vi<\/b> only offers one level of undo. However, you can use <b>U<\/b> (capital U) to undo any changes that were made to the current line; pressing <b>U<\/b> restores the current line to the way it was before you started changing it.<\/p>\n<h2> \tSummary: Making Changes<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\tSPACE<\/td>\n<td> \t\t\t\tadvance the cursor one position<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^W<\/b><\/td>\n<td> \t\t\t\terase a word during insert<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>.<\/b><\/td>\n<td> \t\t\t\trepeats the last change command<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>O<\/b><\/td>\n<td> \t\t\t\topens and inputs a new line, above the current line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>U<\/b><\/td>\n<td> \t\t\t\tundoes the changes you made to the current line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>a<\/b><\/td>\n<td> \t\t\t\tappends text after the cursor<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>c<\/b><\/td>\n<td> \t\t\t\tchanges the object you specify to the text you type in after<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>d<\/b><\/td>\n<td> \t\t\t\tdeletes the object that you specify<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>i<\/b><\/td>\n<td> \t\t\t\tinserts text before the cursor<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>o<\/b><\/td>\n<td> \t\t\t\topens and inputs new lines, below the current line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>u<\/b><\/td>\n<td> \t\t\t\tundoes the last change<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1> \t<a name=\"Rearranging-And-Duplicating-Text\"><\/a>Rearranging and Duplicating Text<\/h1>\n<h2> \tLow-Level Character Motions<\/h2>\n<p class=\"tab\"> \t<b>f<\/b><i>x<\/i> moves the cursor finds the next <i>x<\/i> character on the current line. After that, if you press <b>;<\/b> your cursor will move to the next occurrence of the same character. <b>F<\/b> is a similar command, but searches backwards in the same line, rather than forwards.<\/p>\n<p> \tThe <b>f<\/b> and <b>F<\/b> commands can be combined, for example, with the <b>d<\/b> command. Typing <b>df<\/b><i>x<\/i> will delete everything from the cursor through the next occurrence of <i>x<\/i> in the line. Sometimes you want to delete up to, but not including, the next occurrence of character <i>x<\/i>. In this case, use the command <b>dt<\/b><i>x<\/i>. <b>t<\/b> stands for &quot;to&quot;.<\/p>\n<p> \tThe beginning of the line is represented by zero (&quot;<b>0<\/b>&quot;), the carat (&quot;<b>^<\/b>&quot;) represents the first non-whitespace character on the line, and the end of the line is represented by the dollar sign (&quot;<b>$<\/b>&quot;). If you press <b>^<\/b>, the cursor will be placed at the first non-whitespace character of the line; if you press <b>0<\/b>, the cursor will be placed at the beginning of the line; and if you press <b>$<\/b>, the cursor will be placed at the end of the line.<\/p>\n<p> \tTo delete everything from the cursor to the end of the line, type <b>d$<\/b>. To delete everything from the cursor to the beginning of the line, type <b>d0<\/b>&#8230; and so on.<\/p>\n<h2> \tHigher-Level Text Objects<\/h2>\n<p class=\"tab\"> \tSometimes it&#39;s helpful to move around in units of entire sentences. The <b>(<\/b> and <b>)<\/b> commands move to the beginning of the previous and next sentences, respectively. So the command <b>d)<\/b> deletes everything through the end of the current sentence; and <b>d(<\/b> deletes everything through the beginning of the current sentence, or the entire previous sentence if you&#39;re already at the beginning of a sentence.<\/p>\n<p> \tA sentence is defined as ending at a period (&quot;<b>.<\/b>&quot;), exclamation point (&quot;<b>!<\/b>&quot;), or question mark (&quot;<b>?<\/b>&quot;) which is followed either by the end of the line or a space. Any number of closing <b>)<\/b>, <b>]<\/b>, <b>&quot;<\/b>, and <b>&#39;<\/b> characters may appear after the <b>.<\/b>, <b>?<\/b>, or <b>!<\/b> before the space or the end of the line.<\/p>\n<p> \tThe <b>{<\/b> and <b>}<\/b> commands move over paragraphs, and the operations <b>[[<\/b> and <b>]]<\/b> move over sections. (A &quot;section&quot; can be defined by a special macro, or by a formfeed at the beginning of a line.)<\/p>\n<h2> \tRearranging And Duplicating Text<\/h2>\n<p class=\"tab\"> \tThe editor has a special unnamed buffer where the last deleted or changed-away text is saved, and a set of named buffers <b>a<\/b> through <b>z<\/b> which you can use to save copies of text and to move text around in your file (or files).<\/p>\n<p> \tThe <b>y<\/b> command &quot;yanks&quot; a copy of an object into the unnamed buffer. If preceded by a buffer name, it places this object into the named buffer. The way to specify the buffer is double quotes (<b>&quot;<\/b>), then a letter <b>a<\/b>&#8211;<b>z<\/b>, then the <b>y<\/b> command. So <b>&quot;ay<\/b> will yank an object into the buffer named <b>a<\/b>.<\/p>\n<p> \tText in a buffer (either the unnamed buffer or one of your named buffers) can be pasted into your document with the commands <b>p<\/b> or <b>P<\/b>. <b>p<\/b> will paste the buffer contents after the cursor location (much like an append), and <b>P<\/b> will paste the buffer contents at the cursor location (much like an insert).<\/p>\n<p> \tIf the text which you yank forms part of a line, or is an object such as a sentence which partially spans more than one line, then when you put the text back, it will be placed after the cursor (or before it if you used <b>P<\/b>). If the yanked text forms whole lines, they will be put back as whole lines, without changing the current line. In this case, the paste acts much more like an <b>o<\/b> or <b>O<\/b> command. So, the command <b>YP<\/b> will make a copy of the current line and place you at the location of the copy, which is placed before the current line. <b>Y<\/b> is a convenient abbreviation for <b>yy<\/b>.<\/p>\n<p> \tThe command <b>Yp<\/b> will also make a copy of the current line, and place it after the current line. You can give <b>Y<\/b> a number of lines to yank, and thus duplicate several lines; for instance, <b>3YP<\/b> will duplicate three lines, and place them before the current line.<\/p>\n<p> \tTo move text within the buffer, you need to delete it in one place, and put it back in another. You can precede a delete operation by the name of a buffer in which the text is to be stored, as in <b>&quot;a5dd<\/b>, which deletes 5 lines into the named buffer <b>a<\/b>. You can then move the cursor to the eventual resting place of these lines and do a <b>&quot;ap<\/b> or <b>&quot;aP<\/b> to put them back. In fact, you can switch and edit another file before you put the lines back, by giving a command of the form <b>:e <\/b><i>name<\/i>, where <i>name<\/i> is the name of the other file you want to edit. (You will have to write the contents of the current editor buffer (or discard them) if you have made changes, before the editor will allow you to edit a new file.)<\/p>\n<p> \tAn ordinary delete command saves the text in the unnamed buffer, so that an ordinary paste will place it back in the file. However, the unnamed buffer is lost when you change files, so to move text from one file to another you should use a named buffer.<\/p>\n<h2> \tSummary of Moving And Rearranging Text<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^<\/b><\/td>\n<td> \t\t\t\tFirst non-whitespace character on line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>0<\/b><\/td>\n<td> \t\t\t\tBeginning of the line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>$<\/b><\/td>\n<td> \t\t\t\tEnd of the line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>)<\/b><\/td>\n<td> \t\t\t\tForward to next sentence break<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>(<\/b><\/td>\n<td> \t\t\t\tBackward to previous sentence break<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>}<\/b><\/td>\n<td> \t\t\t\tForward to next paragraph break<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>{<\/b><\/td>\n<td> \t\t\t\tBackward to previous paragraph break<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>]]<\/b><\/td>\n<td> \t\t\t\tForward to next section break<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>[[<\/b><\/td>\n<td> \t\t\t\tBackward to previous section break<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>f<\/b><i>x<\/i><\/td>\n<td> \t\t\t\tFind character <i>x<\/i> forward in the line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>F<\/b><i>x<\/i><\/td>\n<td> \t\t\t\tFind character <i>x<\/i> backward in the line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>p<\/b><\/td>\n<td> \t\t\t\tPaste text after cursor<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>P<\/b><\/td>\n<td> \t\t\t\tPaste text before cursor<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>y<\/b><\/td>\n<td> \t\t\t\tyank<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>Y<\/b><\/td>\n<td> \t\t\t\tyank a whole line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>t<\/b><\/td>\n<td> \t\t\t\tforward to character <i>x<\/i>, for operations<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>T<\/b><i>x<\/i><\/td>\n<td> \t\t\t\tback to character <i>x<\/i>, for operations<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1> \t<a name=\"High-Level-Commands\"><\/a>High Level Commands<\/h1>\n<h2> \tWriting, Quitting, and Editing New Files<\/h2>\n<p class=\"tab\"> \tSo far we have seen how to write our file to disk and quit (<b>ZZ<\/b>), or simply write our file and continue editing(<b>:w<\/b>).<\/p>\n<p> \tIf you have changed your file but you want to quit without saving, use the command <b>:q!<\/b>. The command <b>:q<\/b> quits the editor, but it will only let you do this if you haven&#39;t made any changes since your last write (your last save). The exclamation point, however, tells the editor &quot;yes, I really want to do this.&quot;<\/p>\n<p> \tSimilarly, you can edit another file with the <b>:e<\/b> <i>name<\/i> command, where <i>name<\/i> is the name of the file you want to edit. But the editor won&#39;t let you do this if you have unsaved changes. However, if you use the exclamation mark again (<b>:e!<\/b> <i>name<\/i>), the editor will do as you ask: it will discard your changes and open file <i>name<\/i> for editing.<\/p>\n<p> \tIf you don&#39;t specify a filename, and just use the command <b>:e!<\/b>, the editor will re-load your saved version of the file you&#39;re working on. This is like the &quot;revert&quot; command in other file editors. It will discard your changes, and revert to the last-saved version of the file.<\/p>\n<h2> \tEscaping To The Shell<\/h2>\n<p class=\"tab\"> \tIf you want run a shell command without exiting the editor, you can use the command <b>:!<\/b><i>command<\/i>. The system will run the command <i>command<\/i>, and when the command finishes, the editor will ask you to press Enter before returning you to the editing screen. You can also give another <b>:<\/b> command when it asks you to press Enter; this will run the next command without redrawing the screen.<\/p>\n<p> \tIf you want to drop entirely to your shell&#39;s command prompt, use the command <b>:sh<\/b>. This will drop you into your shell, where you can use it as you normally would; when you&#39;re done, type Control-D (<b>^D<\/b>), and you will be returned to <b>vi<\/b>.<\/p>\n<p> \tOn many systems, you can also simply type <b>^Z<\/b> from within the editor at any time to drop into your shell. This technically puts <b>vi<\/b> in the background. To return to <b>vi<\/b>, type <b>fg<\/b> (&quot;foreground&quot;) at your shell command prompt, and <b>vi<\/b> will become your foreground process again.<\/p>\n<h2> \tMarking And Returning<\/h2>\n<p class=\"tab\"> \tAs already mentioned, the command <b>&#8220;<\/b> (two back quotes) returns you to the previous place after a motion of the cursor by a command such as <b>\/<\/b>, <b>\/<\/b>, or <b>G<\/b>. You can also mark your position in the file with single-letter tags and return to these marks later. The marking is done with the command <b>m<\/b><i>x<\/i>, where <i>x<\/i> is the letter you want to assign to the mark. To return to the place that you marked, you can use the command <b>`<\/b><i>x<\/i><\/p>\n<p> \tFor example, if you type <b>ma<\/b>, you will mark the current cursor position with the letter <b>a<\/b>. Then, if you move the cursor anywhere else in the file, you can always return to that line with the command <b>`a<\/b>. Marks last until you start editing another file, or until you overwrite the mark by setting it somewhere else.<\/p>\n<p> \tWhen using operators such as <b>d<\/b> and referring to marked lines, sometimes you&#39;ll want to refer to the line that you marked, and not the actual cursor position within the line. At any time, you can use <b>&#39;<\/b><i>x<\/i> (as opposed to <b>`<\/b><i>x<\/i>) to refer to the line itself. So, the command <b>d`<\/b><i>a<\/i> will delete everything from the current cursor position up to the exact position at mark <b>a<\/b>, whereas the command <b>d&#39;a<\/b> will delete everything up to (and including) the entire line where mark <b>a<\/b> resides.<\/p>\n<p> \tUsed without an operator, <b>&#39;<\/b><i>x<\/i> moves you to the first non-whitespace character in the line where mark <i>x<\/i> resides.<\/p>\n<h2> \tAdjusting The Screen<\/h2>\n<p class=\"tab\"> \tIf the screen image is messed up for any reason, you can refresh the screen with Control-L (<b>^L<\/b>).<\/p>\n<p> \tIf you want to center the screen on your cursor at any time, type <b>z-<\/b>. To adjust the screen so that the line with your cursor is at the top of the screen, type <b>z<\/b> and press Enter. To adjust the screen so that the line with your cursor is at the bottom of the screen, type <b>z.<\/b>.<\/p>\n<p> \t<b>zz<\/b> is the same as <b>z-<\/b>, and will center the screen so that the line with your cursor is at the center of the screen.<\/p>\n<h1> \t<a name=\"Special-Topics\"><\/a>Special Topics<\/h1>\n<h2> \tSetting Options, and Using Editor Startup Files<\/h2>\n<p class=\"tab\"> \tThe editor has a set of options, which you can set with the <b>:set<\/b> command. To set option <i>opt<\/i> to value <i>val<\/i>, use the command <b>:set<\/b> <i>opt<\/i><b>=<\/b><i>val<\/i>.<\/p>\n<p> \tToggle options can be set with the commands <b>set<\/b> <i>opt<\/i>, and unset with the command <b>set no<\/b><i>opt<\/i>.<\/p>\n<p> \tHere are some of the most useful options you can set:<\/p>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<th> \t\t\t\toption name<\/th>\n<th> \t\t\t\tdefault value<\/th>\n<th> \t\t\t\tdescription<\/th>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>autoindent<\/b><\/td>\n<td> \t\t\t\tnoai<\/td>\n<td> \t\t\t\tSupply indentation automatically<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>autowrite<\/b><\/td>\n<td> \t\t\t\tnoaw<\/td>\n<td> \t\t\t\tAutomatically write to file while editing<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>ignorecase<\/b><\/td>\n<td> \t\t\t\tnoic<\/td>\n<td> \t\t\t\tIgnore case when searching<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>lisp<\/b><\/td>\n<td> \t\t\t\tnolisp<\/td>\n<td> \t\t\t\t<b>(<\/b>, <b>{<\/b>, <b>)<\/b>, and <b>}<\/b> commands deal with S-expressions<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>list<\/b><\/td>\n<td> \t\t\t\tnolist<\/td>\n<td> \t\t\t\tTabs print as <b>^I<\/b>; end of lines marked with <b>$<\/b><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>magic<\/b><\/td>\n<td> \t\t\t\tnomagic<\/td>\n<td> \t\t\t\tThe characters <b>.<\/b>, <b>[<\/b>, and <b>*<\/b> are special (&quot;magical&quot;) in scans<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>number<\/b><\/td>\n<td> \t\t\t\tnonu<\/td>\n<td> \t\t\t\tLines are displayed prefixed with their line numbers<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>paragraphs<\/b><\/td>\n<td> \t\t\t\tpara=IPLPPPQPbpP<\/td>\n<td> \t\t\t\tLI Macro names which start paragraphs<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>redraw<\/b><\/td>\n<td> \t\t\t\tnore<\/td>\n<td> \t\t\t\tSimulate a smart terminal on a dumb terminal<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>sections<\/b><\/td>\n<td> \t\t\t\tsect=NHSHH<\/td>\n<td> \t\t\t\tHU Macro names which start new sections<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>shiftwidth<\/b><\/td>\n<td> \t\t\t\tsw=8<\/td>\n<td> \t\t\t\tShift distance for <b>&lt;<\/b>, <b>&gt;<\/b>, and other &quot;shift&quot; commands<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>showmatch<\/b><\/td>\n<td> \t\t\t\tnosm<\/td>\n<td> \t\t\t\tShow matching <b>(<\/b> or <b>{<\/b> locations as <b>)<\/b> or <b>}<\/b> is typed, for example<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>showmode<\/b><\/td>\n<td> \t\t\t\tnosmd<\/td>\n<td> \t\t\t\tShow input mode description<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>slowopen<\/b><\/td>\n<td> \t\t\t\tslow<\/td>\n<td> \t\t\t\tPostpone display updates during inserts<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>term<\/b><\/td>\n<td> \t\t\t\tdumb<\/td>\n<td> \t\t\t\tThe kind of terminal you are using<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"tab\"> \tThese statements can be placed in the <a href=\"http:\/\/www.computerhope.com\/jargon\/e\/envivari.htm\">environment variable<\/a> <b>EXINIT<\/b>, or can be given while you are running <b>vi<\/b> by preceding them with a <b>:<\/b>, as described above.<\/p>\n<p> \tYou can view a list of all options and their settings by typing <b>:set<\/b> within <b>vi<\/b> at any time. To view the current setting of a particular option, use the command <b>:set<\/b> <i>opt<\/i><b>?<\/b>.<\/p>\n<p> \t<b>set<\/b> can be appreviated as <b>se<\/b>. Multiple options can be set on one line, for instance <b>:se ai aw nu<\/b>.<\/p>\n<p> \tOptions set with <b>:set<\/b> only last for your current editor session.<\/p>\n<p> \tIf you want to place your default settings into the environment variable <b>EXINIT<\/b> so that they are loaded every time you run <b>vi<\/b>, you can specify multiple commands on a single line by separating them with the vertical bar (&quot;<b>|<\/b>&quot;). For instance, if your shell is <a href=\"http:\/\/www.computerhope.com\/unix\/ucsh.htm\"><b>csh<\/b><\/a>, you could set <b>EXINIT<\/b> with the following shell command:<\/p>\n<pre class=\"tab tcy\">setenv EXINIT &#39;set ai aw terse|map @ dd|map # x&#39;<\/pre>\n<h2> \tRecovering Lost Lines<\/h2>\n<p class=\"tab\"> \tYou might have a problem if you delete several lines and then want them back. However, the editor saves the last 9 deleted blocks of text in a set of registers numbered <b>1<\/b> through <b>9<\/b>. You can get the <i>n<\/i>th previous deleted text back in your file by the command <b>&quot;<\/b><i>n<\/i><b>p<\/b>. These are similar to your named buffers, except they refer to the number of the previous block of text that was deleted.<\/p>\n<p> \tUsually, when you type a single period (&quot;<b>.<\/b>&quot;), it repeats the last change you&#39;ve made. As a special case, when this period repeats a change that refers to a numbered buffer, the number is incremented before the command is repeated. Let&#39;s see how this works, and why it&#39;s useful:<\/p>\n<p> \tLet&#39;s say you deleted something important, and you know it&#39;s in one of your nine previous block-deletes, but you&#39;re not sure which one. If you want to go back and look at all nine previously deleted blocks, here&#39;s how you could do it: you could use the command<\/p>\n<pre class=\"tab tcy\">&quot;1p<\/pre>\n<p class=\"tab\"> \tTo paste the contents of the most recently-deleted text (buffer number <b>1<\/b>). If that&#39;s not the text you wanted, you could then undo (<b>u<\/b>) and repeat the command with <b>.<\/b>, pasting the command of buffer <b>2<\/b>. In other words, typing the command<\/p>\n<pre class=\"tab tcy\">&quot;1pu.u.u.u.<\/pre>\n<p class=\"tab\"> \tis the same as typing<\/p>\n<pre class=\"tab tcy\">&quot;1pu&quot;2pu&quot;3pu&quot;4pu&quot;5p<\/pre>\n<p class=\"tab\"> \tand you can go back in the numbered buffers easily until you find the text you want to have back.<\/p>\n<p> \tThe command <b>P<\/b> can, of course, be used instead of <b>p<\/b> in the above example, to place the text before the cursor instead of after it.<\/p>\n<h2> \tRecovering Lost Files<\/h2>\n<p class=\"tab\"> \tIf the system crashes, you can recover the work you were doing to within a few changes. When you get back into your system, use this command to start <b>vi<\/b>:<\/p>\n<pre class=\"tab tcy\">vi -r <i>name<\/i><\/pre>\n<p class=\"tab\"> \tWhere <i>name<\/i> is the name of the file you were editing. This will recover your work to a point as close as possible to where you left off.<\/p>\n<p> \tIf you don&#39;t specify a file with <i>name<\/i> and instead just type<\/p>\n<pre class=\"tab tcy\">vi -r<\/pre>\n<p class=\"tab\"> \tthen you will receive a list of files which can be recovered.<\/p>\n<h2> \tContinuous Text Input<\/h2>\n<p class=\"tab\"> \tWhen you are typing in large amounts of text it is convenient to have lines broken near the right margin automatically. You can cause this to happen by giving the command <b>:se wm=10<\/b>. This causes all lines to be broken at a space at least 10 columns from the right hand edge of the screen.<\/p>\n<p> \tIf the editor breaks an input line and you wish to put it back together you can tell it to join the lines with <b>J<\/b>. You can give <b>J<\/b> a count of the number of lines to be joined as in <b>3J<\/b> to join 3 lines. The editor supplies white space, if appropriate, at the juncture of the joined lines, and leaves the cursor at this white space. You can kill the white space with <b>x<\/b> if you don&#39;t want it.<\/p>\n<h2> \tFeatures For Editing Programs<\/h2>\n<p class=\"tab\"> \tThe editor has a number of commands for editing programs. The thing that most distinguishes editing of programs from editing of text is the indented structure to the body of the program. The editor has an <b>autoindent<\/b> facility for helping you generate correctly indented programs.<\/p>\n<p> \tTo enable this facility you can give the command <b>:se ai<\/b>. Now try opening a new line with <b>o<\/b> and type some characters on the line after a few tabs. If you now start another line, notice that the editor supplies white space at the beginning of the line to line it up with the previous line. You cannot backspace over this indentation, but you can use <b>^D<\/b> key to backtab over the supplied indentation.<\/p>\n<p> \tEach time you type <b>^D<\/b> you back up one position, normally to an 8 column boundary. This amount is settable; the editor has an option called <b>shiftwidth<\/b> which you can set to change this value. Try giving the command <b>:se sw=4<\/b> and then experimenting with <b>autoindent<\/b> again.<\/p>\n<p> \tFor shifting lines in the program left and right, there are operators <b>&lt;<\/b> and <b>&gt;<\/b>. These shift the lines you specify right or left by one shiftwidth. Try <b>&lt;&lt;<\/b> and <b>&gt;&gt;<\/b> which shift one line left or right, and <b>&lt;L<\/b> and <b>&gt;L<\/b> shifting the rest of the display left and right.<\/p>\n<p> \tIf you have a complicated expression and wish to see how the parentheses match, put the cursor at a left or right parenthesis and hit <b>%<\/b>. This will show you the matching parenthesis. This works also for braces <b>{<\/b> and <b>}<\/b>, and brackets <b>[<\/b> and <b>]<\/b>.<\/p>\n<p> \tIf you are editing <a href=\"http:\/\/www.computerhope.com\/jargon\/c\/c.htm\">C<\/a> programs, you can use the <b>[[<\/b> and <b>]]<\/b> keys to advance or retreat to a line starting with a <b>{<\/b>, i.e. a function declaration at a time. When <b>]]<\/b> is used with an operator it stops after a line which starts with <b>}<\/b>; this is sometimes useful with <b>y]]<\/b>.<\/p>\n<h2> \tFiltering Portions of the Buffer<\/h2>\n<p class=\"tab\"> \tYou can run system commands over portions of the buffer using the operator <b>!<\/b> (the exclamation point). Essentially, it sends a section of your file as <a href=\"http:\/\/www.computerhope.com\/jargon\/s\/stdin.htm\">standard input<\/a> to a shell command, then replaces that portion of your text with the standard output of the command.<\/p>\n<p> \tAll togehter, the way to specify what text to send and what command to send it to, is <b>!<\/b><i>(movement-specifier) command-name<\/i>. The <i>movement-specifier<\/i> could be <b>w<\/b> for operating on the next word, for instance, or <b>}<\/b> for the next paragraph, etc. The <i>command-name<\/i> is the shell command, and any arguments it may take.<\/p>\n<p> \tThis is especially useful for sorting using the <a href=\"http:\/\/www.computerhope.com\/unix\/usort.htm\"><b>sort<\/b><\/a> command. You can use this to sort lines in your file. For instance, if you were to type in a list of random words, one per line, and end them with a blank line, then you backed up to the beginning of the list and gave the command <b>!}sort<\/b>, this would sort the data you just typed in, right before your eyes. This is a very powerful function! Try it for yourself.<\/p>\n<h2> \tCommands For Editing LISP Code<\/h2>\n<p class=\"tab\"> \tIf you are editing a <a href=\"http:\/\/www.computerhope.com\/jargon\/l\/lisp.htm\">LISP<\/a> program you should set the option <b>lisp<\/b> by doing <b>:se lisp<\/b>. This changes the <b>(<\/b> and <b>)<\/b> commands to move backward and forward over s-expressions. The <b>{<\/b> and <b>}<\/b> commands are like <b>(<\/b> and <b>)<\/b> but don&#39;t stop at atoms. These can be used to skip to the next list, or through a <a href=\"http:\/\/www.computerhope.com\/jargon\/c\/comment.htm\">comment<\/a> quickly.<\/p>\n<p> \tThe <b>autoindent<\/b> option works differently for LISP, supplying indent to align at the first <a href=\"http:\/\/www.computerhope.com\/jargon\/a\/argument.htm\">argument<\/a> to the last open list. If there is no such argument then the indent is two spaces more than the last level.<\/p>\n<p> \tThere is another option which is useful for typing in LISP, the <b>showmatch<\/b> option. Try setting it with <b>:se sm<\/b> and then try typing a &quot;<b>(<\/b>&quot;, some words, and then a &quot;<b>)<\/b>&quot;. Notice that the cursor shows the position of the &quot;<b>(<\/b>&quot; which matches the &quot;<b>)<\/b>&quot; briefly. This happens only if the matching &quot;<b>(<\/b>&quot; is on the screen, and the cursor stays there for at most one second.<\/p>\n<p> \tThe editor also has an operator to realign existing lines as though they had been typed in with <b>lisp<\/b> and <b>autoindent<\/b> set. This is the <b>=<\/b> operator. Try the command <b>=%<\/b> at the beginning of a <a href=\"http:\/\/www.computerhope.com\/jargon\/f\/function.htm\">function<\/a>. This will realign all the lines of the function declaration.<\/p>\n<p> \tWhen you are editing LISP, the <b>[[<\/b> and <b>]]<\/b> advance and retreat to lines beginning with a <b>(<\/b>, and are useful for dealing with entire function definitions.<\/p>\n<h2> \tMacros<\/h2>\n<p class=\"tab\"> \t<b>vi<\/b> has a parameterless <a href=\"http:\/\/www.computerhope.com\/jargon\/m\/macro.htm\">macro<\/a> facility, which lets you set it up so that when you hit a single keystroke, the editor will act as though you had hit some longer sequence of keys. You can set this up if you find yourself typing the same sequence of commands repeatedly.<\/p>\n<p> \tThere are two general kinds of macros:<\/p>\n<ol>\n<li> \t\tOnes where you put the macro body in a named macro buffer <i>x<\/i>. You can then type <b>@<\/b><i>x<\/i> to invoke the macro. The <b>@<\/b> may be followed by another <b>@<\/b> to repeat the last macro.<\/li>\n<li> \t\tYou can use the map command from <b>vi<\/b> (typically in your <b>EXINIT<\/b> environment variable) with a command of the form:\n<pre class=\"tcy\">:map lhs rhsCR<\/pre>\n<p> \t\tmapping <b>lhs<\/b> into <b>rhs<\/b>. There are restrictions: <b>lhs<\/b> should be one keystroke (either 1 character or one function key) since it must be entered within one second (unless <b>notimeout<\/b> is set, in which case you can type it as slowly as you wish, and <b>vi<\/b> will wait for you to finish it before it echoes anything). The lhs can be no longer than 10 characters, the <b>rhs<\/b> no longer than 100. To get a space, tab or <a href=\"http:\/\/www.computerhope.com\/jargon\/n\/newline.htm\">newline<\/a> into <b>lhs<\/b> or <b>rhs<\/b> you should escape them with a <b>^V<\/b>. (It may be necessary to double the <b>^V<\/b> if the map command is given inside <b>vi<\/b>, rather than in <b>ex<\/b>.) Spaces and tabs inside the <b>rhs<\/b> need not be escaped.<\/li>\n<\/ol>\n<p class=\"tab\"> \tThus to make the <b>q<\/b> key write and exit the editor, you can give the command<\/p>\n<pre class=\"tab tcy\">:map q :wq^V^VCR CR<\/pre>\n<p class=\"tab\"> \twhich means that whenever you type <b>q<\/b>, it will be as though you had typed the four characters <b>:wqCR<\/b>. A <b>^V<\/b>&#39;s is needed because without it the carriage return would end the <b>:<\/b> command, rather than becoming part of the map definition. There are two <b>^V<\/b>&#39;s because from within <b>vi<\/b>, two <b>^V<\/b>&#39;s must be typed to get one. The first CR is part of the <b>rhs<\/b>, the second terminates the <b>:<\/b> command.<\/p>\n<p> \tMacros can be deleted with<\/p>\n<pre class=\"tab tcy\">unmap lhs<\/pre>\n<p class=\"tab\"> \tIf the <b>lhs<\/b> of a macro is &ldquo;<b>#0<\/b>&rdquo; through &ldquo;<b>#9<\/b>&rdquo;, this maps the particular function key instead of the 2 character &ldquo;<b>#<\/b>&rdquo; sequence. So that terminals without function keys can access such definitions, the form &ldquo;<b>#x<\/b>&rdquo; will mean function key <b>x<\/b> on all terminals (and need not be typed within one second.) The character &ldquo;<b>#<\/b>&rdquo; can be changed by using a macro in the usual way:<\/p>\n<pre class=\"tab tcy\">:map ^V^V^I #<\/pre>\n<p class=\"tab\"> \tto use tab, for example. (This won&#39;t affect the <b>map<\/b> command, which still uses <b>#<\/b>, but just the invocation from visual mode.)<\/p>\n<p> \tThe <b>undo<\/b> command reverses an entire macro call as a unit, if it made any changes.<\/p>\n<p> \tPlacing a &quot;<b>!<\/b>&quot; after the word map causes the mapping to apply to input mode, rather than command mode. Thus, to arrange for <b>^T<\/b> to be the same as 4 spaces in input mode, you can type:<\/p>\n<pre class=\"tab tcy\">:map! ^T ^Vb\/b\/b\/b\/<\/pre>\n<p class=\"tab\"> \twhere <b>b\/<\/b> is a blank. The <b>^V<\/b> is necessary to prevent the blanks from being taken as white space between the <b>lhs<\/b> and <b>rhs<\/b>.<\/p>\n<h2> \tWord Abbreviations<\/h2>\n<p class=\"tab\"> \tA feature similar to macros in input mode is word abbreviation. This allows you to type a short word and have it expanded into a longer word or words. The commands are <b>:abbreviate<\/b> and <b>:unabbreviate<\/b> (<b>:ab<\/b> and <b>:una<\/b>) and have the same syntax as <b>:map<\/b>. For example:<\/p>\n<pre class=\"tab tcy\">:ab eecs Electrical Engineering and Computer Sciences<\/pre>\n<p class=\"tab\"> \tcauses the word &quot;<b>eecs<\/b>&quot; to always be changed into the phrase &quot;<b>Electrical Engineering and Computer Sciences<\/b>&quot;. Word abbreviation is different from macros in that only whole words are affected. If &quot;<b>eecs<\/b>&quot; were typed as part of a larger word, it would be left alone. Also, the partial word is echoed as it is typed. There is no need for an abbreviation to be a single keystroke, as it should be with a macro.<\/p>\n<h1> \t<a name=\"Technical-Details\"><\/a>Technial Details<\/h1>\n<h2> \tLine Representation In The Display<\/h2>\n<p class=\"tab\"> \tThe editor folds long logical lines onto many physical lines in the display. Commands which advance lines advance logical lines and will skip over all the segments of a line in one motion. The command <b>|<\/b> moves the cursor to a specific column, and may be useful for getting near the middle of a long line to split it in half.<\/p>\n<p> \tThe editor only puts full lines on the display; if there is not enough room on the display to fit a logical line, the editor leaves the physical line empty, placing only an <b>@<\/b> on the line as a place holder. When you delete lines on a dumb terminal, the editor will often just clear the lines to <b>@<\/b> to save time (rather than rewriting the rest of the screen.) You can always maximize the information on the screen by giving the <b>^R<\/b> command.<\/p>\n<p> \tIf you wish, you can have the editor place line numbers before each line on the display. Give the command <b>:se nu<\/b> to enable this, and the command <b>:se nonu<\/b> to turn it off. You can have tabs represented as <b>^I<\/b> and the ends of lines indicated with &quot;<b>$<\/b>&quot; by giving the command <b>:se list<\/b>; <b>:se nolist<\/b> turns this off.<\/p>\n<p> \tFinally, lines consisting of only the character &quot;<b>~<\/b>&quot; are displayed when the last line in the file is in the middle of the screen. These represent physical lines which are past the logical end of file.<\/p>\n<h2> \tMore File Manipulation Commands<\/h2>\n<p class=\"tab\"> \tThe following table lists the file manipulation commands which you can use when you are in <b>vi<\/b>.<\/p>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:w<\/b><\/td>\n<td> \t\t\t\twrite back changes<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:wq<\/b><\/td>\n<td> \t\t\t\twrite and quit<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>\ud83d\ude21<\/b><\/td>\n<td> \t\t\t\twrite (if necessary) and quit (same as <b>ZZ<\/b>).<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:e<\/b> <i>name<\/i><\/td>\n<td> \t\t\t\tedit file <i>name<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:e!<\/b><\/td>\n<td> \t\t\t\treedit, discarding changes<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:e +<\/b> <i>name<\/i><\/td>\n<td> \t\t\t\tedit, starting at end<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:e +<\/b><i>n<\/i><\/td>\n<td> \t\t\t\tedit, starting at line <i>n<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:e #<\/b><\/td>\n<td> \t\t\t\tedit alternate file<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:w<\/b> <i>name<\/i><\/td>\n<td> \t\t\t\twrite file <i>name<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:w!<\/b> <i>name<\/i><\/td>\n<td> \t\t\t\toverwrite file <i>name<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:<i>x<\/i><b>,<\/b><i>y<\/i><b>w<\/b> <i>name<\/i><\/b><\/td>\n<td> \t\t\t\twrite lines <i>x<\/i> through <i>y<\/i> to <i>name<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:r<\/b> <i>name<\/i><\/td>\n<td> \t\t\t\tread file <i>name<\/i> into buffer<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:r !<\/b><i>cmd<\/i><\/td>\n<td> \t\t\t\tread output of <i>cmd<\/i> into buffer<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:<\/b><i>n<\/i><\/td>\n<td> \t\t\t\tedit next file in argument list<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:<\/b><i>n<\/i><b>!<\/b><\/td>\n<td> \t\t\t\tedit next file, discarding changes to current<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:<\/b><i>n<\/i> <i>args<\/i><\/td>\n<td> \t\t\t\tspecify new argument list<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:ta<\/b> <i>tag<\/i><\/td>\n<td> \t\t\t\tedit file containing tag <i>tag<\/i>, at <i>tag<\/i><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"tab\"> \tAll of these commands are followed by a CR or ESC. The most basic commands are <b>:w<\/b> and <b>:e<\/b>. A normal editing session on a single file will end with a <b>ZZ<\/b> command. If you are editing for a long period of time you can give <b>:w<\/b> commands occasionally after major amounts of editing, and then finish with a <b>ZZ<\/b>. When you edit more than one file, you can finish with one with a <b>:w<\/b> and start editing a new file by giving a <b>:e<\/b> command, or set <b>autowrite<\/b> and use <b>:n<\/b> <i>file<\/i>.<\/p>\n<p> \tIf you make changes to the editor&#39;s copy of a file, but do not wish to write them back, then you must give an <b>!<\/b> after the command you would otherwise use; this forces the editor to discard any changes you have made. Use this carefully.<\/p>\n<p> \tThe <b>:e<\/b> command can be given a <b>+<\/b> argument to start at the end of the file, or a <b>+<\/b><i>n<\/i> argument to start at line <i>n<\/i>. In actuality, <i>n<\/i> may be any editor command not containing a space, usefully a scan like <b>+\/<\/b><i>pat<\/i> or <b>+?<\/b><i>pat<\/i>. In forming new names to the <b>e<\/b> command, you can use the character <b>%<\/b> which is replaced by the current file name, or the character <b>#<\/b> which is replaced by the alternate file <i>name<\/i>. The alternate file <i>name<\/i> is generally the last name you typed other than the current file. Thus if you try to do a <b>:e<\/b> and get a diagnostic that you haven&#39;t written the file, you can give a <b>:w<\/b> command and then a <b>:e #<\/b> command to redo the previous <b>:e<\/b>.<\/p>\n<p> \tYou can write part of the buffer to a file by finding out the lines that bound the range to be written using <b>^G<\/b>, and giving these numbers after the <b>:<\/b> and before the <b>w<\/b>, separated by <b>,<\/b>&#39;s. You can also mark these lines with <b>m<\/b> and then use an address of the form <b>&#39;<\/b><i>x<\/i>,<b>&#39;<\/b><i>y<\/i> on the <b>w<\/b> command here.<\/p>\n<p> \tYou can read another file into the buffer after the current line by using the <b>:r<\/b> command. You can similarly read in the output from a command, just use <b>!cmd<\/b> instead of a file name.<\/p>\n<p> \tIf you wish to edit a set of files in succession, you can give all the names on the command line, and then edit each one in turn using the command <b>:n<\/b>. It is also possible to respecify the list of files to be edited by giving the <b>:n<\/b> command a list of file names, or a pattern to be expanded as you would have given it on the initial <b>vi<\/b> command.<\/p>\n<p> \tIf you are editing large programs, you will find the <b>:ta<\/b> command very useful. It utilizes a data base of function names and their locations, which can be created by programs such as <a href=\"http:\/\/www.computerhope.com\/unix\/uctags.htm\"><b>ctags<\/b><\/a>, to quickly find a function whose name you give. If the <b>:ta<\/b> command will require the editor to switch files, then you must <b>:w<\/b> or abandon any changes before switching. You can repeat the <b>:ta<\/b> command without any arguments to look for the same tag again.<\/p>\n<h2> \tMore About Searching For Strings<\/h2>\n<p class=\"tab\"> \tWhen you are searching for strings in the file with <b>\/<\/b> and <b>?<\/b>, the editor normally places you at the next or previous occurrence of the string. If you are using an operator such as <b>d<\/b>, <b>c<\/b> or <b>y<\/b>, then you may well wish to affect lines up to the line before the line containing the pattern. You can give a search of the form <b>\/<\/b><i>pat<\/i><b>\/-<\/b><i>n<\/i> to refer to the <i>n<\/i>&#39;th line before the next line containing <i>pat<\/i>, or you can use <b>+<\/b> instead of <b>&#8211;<\/b> to refer to the lines after the one containing <i>pat<\/i>. If you don&#39;t give a line offset, then the editor will affect characters up to the match place, rather than whole lines; thus use &ldquo;<b>+0<\/b>&rdquo; to affect to the line which matches.<\/p>\n<p> \tYou can have the editor ignore the case of words in the searches it does by giving the command <b>:se ic<\/b>. The command <b>:se noic<\/b> turns this off.<\/p>\n<p> \tStrings given to searches may actually be <a href=\"http:\/\/www.computerhope.com\/jargon\/r\/regex.htm\">regular expressions<\/a>. If you do not want or need this facility, you should<\/p>\n<pre class=\"tab tcy\">set nomagic<\/pre>\n<p class=\"tab\"> \tin your <b>EXINIT<\/b>. In this case, only the characters <b>^<\/b> and <b>$<\/b> are special in patterns. The character <b>\\<\/b> is also then special (as it is most everywhere in the system), and may be used to get at the an extended pattern matching facility. It is also necessary to use a <b>\\<\/b> before a <b>\/<\/b> in a forward scan or a <b>?<\/b> in a backward scan, in any case. The following table gives the extended forms when magic is set.<\/p>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^<\/b><\/td>\n<td> \t\t\t\tat beginning of pattern, matches beginning of line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>$<\/b><\/td>\n<td> \t\t\t\tat end of pattern, matches end of line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>.<\/b><\/td>\n<td> \t\t\t\tmatches any character<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>\\&lt;<\/b><\/td>\n<td> \t\t\t\tmatches the beginning of a word<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>\\&gt;<\/b><\/td>\n<td> \t\t\t\tmatches the end of a word<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>[<\/b><i>str<\/i><b>]<\/b><\/td>\n<td> \t\t\t\tmatches any single character in <i>str<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>[<\/b><i>str<\/i><b>]<\/b><\/td>\n<td> \t\t\t\tmatches any single character not in <i>str<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>[<\/b><i>x<\/i><b>&#8211;<\/b><i>y<\/i><b>]<\/b><\/td>\n<td> \t\t\t\tmatches any character between <i>x<\/i> and <i>y<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>*<\/b><\/td>\n<td> \t\t\t\tmatches any number of the preceding pattern<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"tab\"> \tIf you use <b>nomagic<\/b> mode, then the <b>. [<\/b> and <b>*<\/b> primitives are given with a preceding <b>\\<\/b>.<\/p>\n<h2> \tMore About Input Mode<\/h2>\n<p class=\"tab\"> \tThere are a number of characters which you can use to make corrections during input mode. These are summarized in the following table.<\/p>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^H<\/b><\/td>\n<td> \t\t\t\tdeletes the last input character<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^W<\/b><\/td>\n<td> \t\t\t\tdeletes the last input word, defined as by <b>b<\/b><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\terase<\/td>\n<td> \t\t\t\tyour erase character, same as <b>^H<\/b><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\tkill<\/td>\n<td> \t\t\t\tyour kill character, deletes the input on this line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>\\<\/b><\/td>\n<td> \t\t\t\tescapes a following <b>^H<\/b> and your erase and kill<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\tESC<\/td>\n<td> \t\t\t\tends an insertion<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\tDEL<\/td>\n<td> \t\t\t\tinterrupts an insertion, terminating it abnormally<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\tCR<\/td>\n<td> \t\t\t\tstarts a new line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^D<\/b><\/td>\n<td> \t\t\t\tbacktabs over autoindent<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>0^D<\/b><\/td>\n<td> \t\t\t\tkills all the autoindent<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^^D<\/b><\/td>\n<td> \t\t\t\t(caret-control-D) same as <b>0^D<\/b>, but restores indent next line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^V<\/b><\/td>\n<td> \t\t\t\tquotes the next non-printing character into the file<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"tab\"> \tThe most usual way of making corrections to input is by typing <b>^H<\/b> to correct a single character, or by typing one or more <b>^W<\/b>&#39;s to back over incorrect words. If you use <b>#<\/b> as your erase character in the normal system, it will work like <b>^H<\/b>.<\/p>\n<p> \tYour system kill character, normally <b>@<\/b>, <b>^X<\/b> or <b>^U<\/b>, will erase all the input you have given on the current line. In general, you can neither erase input back around a line boundary nor can you erase characters which you did not insert with this insertion command. To make corrections on the previous line after a new line has been started you can hit ESC to end the insertion, move over and make the correction, and then return to where you were to continue. The command <b>A<\/b> which appends at the end of the current line is often useful for continuing.<\/p>\n<p> \tIf you wish to type in your erase or kill character (say <b>#<\/b> or <b>@<\/b>) then you must precede it with a <b>\\<\/b>, just as you would do at the normal system command level. A more general way of typing non-printing characters into the file is to precede them with a <b>^V<\/b>. The <b>^V<\/b> echoes as a <b>^<\/b> character on which the cursor rests. This indicates that the editor expects you to type a control character. In fact you may type any character and it will be inserted into the file at that point.<\/p>\n<p> \tIf you are using <b>autoindent<\/b> you can backtab over the indent which it supplies by typing a <b>^D<\/b>. This backs up to a <b>shiftwidth<\/b> boundary. This only works immediately after the supplied <b>autoindent<\/b>.<\/p>\n<p> \tWhen you are using <b>autoindent<\/b> you may wish to place a label at the left margin of a line. The way to do this easily is to type <b>^<\/b> and then <b>^D<\/b>. The editor will move the cursor to the left margin for one line, and restore the previous indent on the next. You can also type a <b>0<\/b> followed immediately by a <b>^D<\/b> if you wish to kill all the indent and not have it come back on the next line.<\/p>\n<h2> \tUppercase-Only Terminals<\/h2>\n<p class=\"tab\"> \tIf your terminal has only upper case, you can still use <b>vi<\/b> by using the normal system convention for typing on such a terminal. Characters which you normally type are converted to lower case, and you can type upper case letters by preceding them with a <b>\\<\/b>. The characters <b>{<\/b> <b>~<\/b> <b>}<\/b> <b>|<\/b> <b>`<\/b> are not available on such terminals, but you can escape them as <b>\\(<\/b> <b>\\^<\/b> <b>\\)<\/b> <b>\\!<\/b> <b>\\&#39;<\/b>. These characters are represented on the display in the same way they are typed.<\/p>\n<h2> \tVi and Ex<\/h2>\n<p class=\"tab\"> \t<b>vi<\/b> is actually one mode of editing within the editor <a href=\"http:\/\/www.computerhope.com\/unix\/uex.htm\"><b>ex<\/b><\/a>. When you are running <b>vi<\/b> you can escape to the line oriented editor of <b>ex<\/b> by giving the command <b>Q<\/b>. All of the <b>:<\/b> commands which were introduced above are available in <b>ex<\/b>. Likewise, most <b>ex<\/b> commands can be invoked from <b>vi<\/b> using <b>:<\/b>. Just give them without the <b>:<\/b> and follow them with a CR.<\/p>\n<p> \tIn rare instances, an internal error may occur in <b>vi<\/b>. In this case you will get a diagnostic and be left in the command mode of <b>ex<\/b>. You can then save your work and quit if you wish by giving a command <b>x<\/b> after the <b>:<\/b> which <b>ex<\/b> prompts you with, or you can reenter <b>vi<\/b> by giving <b>ex<\/b> a <b>vi<\/b> command.<\/p>\n<p> \tThere are a number of things which you can do more easily in <b>ex<\/b> than in <b>vi<\/b>. Systematic changes in line-oriented material are particularly easy. You can read the advanced editing documents for the editor <b>ed<\/b> to find out a lot more about this style of editing. Experienced users often mix their use of <b>ex<\/b> command mode and <b>vi<\/b> command mode to speed the work they are doing.<\/p>\n<h1> \t<a name=\"Quick-Reference\"><\/a>Quick Reference<\/h1>\n<p class=\"tab\"> \tThis is a summary of all the most useful <b>vi<\/b> commands. Refer to it any time you need to remember any of <b>vi<\/b>&#39;s functions quickly, and at a glance.<\/p>\n<h2> \tEntering\/Leaving the Editor<\/h2>\n<p class=\"tab\"> \tFrom the command line:<\/p>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>vi<\/b> <i>name<\/i><\/td>\n<td> \t\t\t\tlaunch <b>vi<\/b>, and load the file <i>name<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>vi<\/b> <b>+<\/b> <i>n<\/i> <i>name<\/i><\/td>\n<td> \t\t\t\tlaunch <b>vi<\/b>, and load file <i>name<\/i>, placing the cursor at line <i>n<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>vi<\/b> <b>-t<\/b> <i>tag<\/i><\/td>\n<td> \t\t\t\tlaunch <b>vi<\/b>, and start editing at <i>tag<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>vi<\/b> <b>-r<\/b><\/td>\n<td> \t\t\t\tlist files that can be recovered<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>vi<\/b> <b>-r<\/b> <i>name<\/i><\/td>\n<td> \t\t\t\tlaunch <b>vi<\/b>, and recover previously-edited file <i>name<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>vi<\/b> <i>name1<\/i> <i>name2<\/i> <b>&#8230;<\/b><\/td>\n<td> \t\t\t\tlaunch <b>vi<\/b>, loading file <i>name1<\/i> for editing; any other files named are loaded with the <b>:n<\/b> command<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>vi<\/b> <b>-R<\/b> <i>name<\/i><\/td>\n<td> \t\t\t\tlaunch <b>vi<\/b>, and load file <i>name<\/i> in <a href=\"http:\/\/www.computerhope.com\/jargon\/r\/readonly.htm\">read-only<\/a> mode<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"tab\"> \tFrom within <b>vi<\/b>:<\/p>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>ZZ<\/b><\/td>\n<td> \t\t\t\texit from <b>vi<\/b>, saving changes<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^Z<\/b><\/td>\n<td> \t\t\t\tbackground <b>vi<\/b> and return to the command shell. Resume foreground <b>vi<\/b> operation with the <b>fg<\/b> shell builtin command<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \tFile Manipulation<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:w<\/b><\/td>\n<td> \t\t\t\twrite changes (save the file)<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:wq<\/b><\/td>\n<td> \t\t\t\twrite changes (save) and quit<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:q<\/b><\/td>\n<td> \t\t\t\tquit immediately, if there are no unsaved changes<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:q!<\/b><\/td>\n<td> \t\t\t\tquit immediately, discarding any unsaved changes<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:e<\/b> <i>name<\/i><\/td>\n<td> \t\t\t\tedit file <i>name<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:e!<\/b><\/td>\n<td> \t\t\t\trevert to the last-saved version of the current file<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:e<\/b> <b>+<\/b> <i>name<\/i><\/td>\n<td> \t\t\t\tload file <i>name<\/i> for editing, placing the cursor at the end of the file<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:e<\/b> <b>+<\/b><i>n<\/i> <i>name<\/i><\/td>\n<td> \t\t\t\tload file <i>name<\/i> for editing, starting at line <i>n<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:e<\/b> <b>#<\/b><\/td>\n<td> \t\t\t\tedit alternate file<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^^<\/b><\/td>\n<td> \t\t\t\t(control-caret). synonym for <b>:e #<\/b><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:w<\/b> <i>name<\/i><\/td>\n<td> \t\t\t\twrite to file <i>name<\/i> (save as&#8230;)<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:w!<\/b> <i>name<\/i><\/td>\n<td> \t\t\t\toverwrite file <i>name<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:sh<\/b><\/td>\n<td> \t\t\t\tdrop to command line shell; <b>^D<\/b> to return<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:!<\/b><i>cmd<\/i><\/td>\n<td> \t\t\t\trun shell command <i>cmd<\/i>, then return to <b>vi<\/b><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:n<\/b><\/td>\n<td> \t\t\t\tedit next file that was specified as an argument to <b>vi<\/b><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:n<\/b> <i>args<\/i><\/td>\n<td> \t\t\t\tspecify new argument list of files for <b>vi<\/b> to edit<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:f<\/b><\/td>\n<td> \t\t\t\tshow current file being edited, and current line count<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^G<\/b><\/td>\n<td> \t\t\t\tsynonym for <b>:f<\/b><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>:ta<\/b> <i>tag<\/i><\/td>\n<td> \t\t\t\tto tag file entry <i>tag<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^]<\/b><\/td>\n<td> \t\t\t\tsame as <b>:ta<\/b>, and the following word is the <i>tag<\/i><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \tPositioning Within File<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^F<\/b><\/td>\n<td> \t\t\t\tposition forward one screenful<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^B<\/b><\/td>\n<td> \t\t\t\tposition backward one screenful<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^D<\/b><\/td>\n<td> \t\t\t\tscroll down one half-screenful<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^U<\/b><\/td>\n<td> \t\t\t\tscroll up one half-screenful<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<i>num<\/i><b>G<\/b><\/td>\n<td> \t\t\t\tgoto line <i>num<\/i> (the last line if <i>num<\/i> not specified)<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>\/<\/b><i>pat<\/i><\/td>\n<td> \t\t\t\tsearch for next occurrence of pattern <i>pat<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>?<\/b><i>pat<\/i><\/td>\n<td> \t\t\t\tsearch for previous occurrence of pattern <i>pat<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>n<\/b><\/td>\n<td> \t\t\t\trepeat last search, in last search direction<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>N<\/b><\/td>\n<td> \t\t\t\trepeat last search, in the opposite of last search direction<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>\/<\/b><i>pat<\/i><b>\/+<\/b><i>n<\/i><\/td>\n<td> \t\t\t\tsearch to the <i>n<\/i>th line after next occurrence of pattern <i>pat<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>?<\/b><i>pat<\/i><b>?-<\/b><i>n<\/i><\/td>\n<td> \t\t\t\tsearch to the <i>n<\/i>th line before the previous occurence of pattern <i>pat<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>]]<\/b><\/td>\n<td> \t\t\t\tmove to next section\/function<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>[[<\/b><\/td>\n<td> \t\t\t\tmove to previous section\/function<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>%<\/b><\/td>\n<td> \t\t\t\tfind matching <b>(<\/b>, <b>)<\/b>, <b>{<\/b>, or <b>}<\/b><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \tInsert and Replace<\/h2>\n<p class=\"tab\"> \tThe <b>ESC<\/b> key exits each of the following text-entry modes, except for <b>r<\/b>, which is only used to enter a single character.<\/p>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>i<\/b><\/td>\n<td> \t\t\t\tinsert mode: text is inserted before the cursor<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>a<\/b><\/td>\n<td> \t\t\t\tappend mode: text is appended after the cursor<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>A<\/b><\/td>\n<td> \t\t\t\ttext is appended at the end of the line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>I<\/b><\/td>\n<td> \t\t\t\ttext is inserted at the beginning of the line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>o<\/b><\/td>\n<td> \t\t\t\topen a new line, after the current line, for text entry<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>O<\/b><\/td>\n<td> \t\t\t\topen a new line, before the current line, for text entry<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>r<\/b><i>x<\/i><\/td>\n<td> \t\t\t\treplace a the character under the cursor with character <i>x<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>R<\/b><\/td>\n<td> \t\t\t\treplace multiple characters<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \tLine Positioning<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>H<\/b><\/td>\n<td> \t\t\t\tmove cursor to the first (&quot;home&quot;) line of the window<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>L<\/b><\/td>\n<td> \t\t\t\tmove cursor to the last line of the window<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>M<\/b><\/td>\n<td> \t\t\t\tmove cursor to the middle line of the window<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>+<\/b><\/td>\n<td> \t\t\t\tmove cursor to the first non-whitespace character of the next line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>&#8211;<\/b><\/td>\n<td> \t\t\t\tmove cursor to the first non-whitespace character of the previous line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>CR<\/b><\/td>\n<td> \t\t\t\t(carriage return\/the Enter key.) same as <b>+<\/b><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>down<\/b> or <b>j<\/b><\/td>\n<td> \t\t\t\tnext line, same column<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>up<\/b> or <b>k<\/b><\/td>\n<td> \t\t\t\tprevious line, same column<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \tCharacter Positioning<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^<\/b><\/td>\n<td> \t\t\t\tmove cursor to first non-whitespace character on the line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>0<\/b><\/td>\n<td> \t\t\t\tmove cursor to beginning of line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>$<\/b><\/td>\n<td> \t\t\t\tmove cursor to end of line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>right<\/b> or <b>l<\/b> or <b>SPACE<\/b><\/td>\n<td> \t\t\t\tmove cursor forward one character<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>left<\/b> or <b>h<\/b> or <b>^H<\/b><\/td>\n<td> \t\t\t\tmove cursor back one character<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>f<\/b><i>x<\/i><\/td>\n<td> \t\t\t\tfind the next occurrence of character <i>x<\/i> in the line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>F<\/b><i>x<\/i><\/td>\n<td> \t\t\t\tfind the previous occurrence of character <i>x<\/i> in the line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>t<\/b><i>x<\/i><\/td>\n<td> \t\t\t\tmove up to <i>x<\/i> forward<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>T<\/b><i>x<\/i><\/td>\n<td> \t\t\t\tmove back to <i>x<\/i> backward<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>;<\/b><\/td>\n<td> \t\t\t\trepeat last <b>f<\/b>, <b>F<\/b>, <b>t<\/b>, or <b>T<\/b><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>,<\/b><\/td>\n<td> \t\t\t\tinverse of <b>;<\/b><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<i>num<\/i><b>|<\/b><\/td>\n<td> \t\t\t\tMove to column <i>num<\/i><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \tOperators<\/h2>\n<p class=\"tab\"> \t(Each of these commands can be used twice to affect entire lines):<\/p>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>d<\/b><\/td>\n<td> \t\t\t\tdelete<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>c<\/b><\/td>\n<td> \t\t\t\tchange (like delete, but places you in insert mode to enter the text it should change to)<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>&lt;<\/b><\/td>\n<td> \t\t\t\tshift line left <b>shiftwidth<\/b> number of spaces<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>&gt;<\/b><\/td>\n<td> \t\t\t\tshift line right <b>shiftwidth<\/b> number of spaces<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>!<\/b><i>(movement-command)<\/i><i>shell-command<\/i><\/td>\n<td> \t\t\t\tfilter text through a shell command<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>=<\/b><\/td>\n<td> \t\t\t\tindent for LISP<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>y<\/b><\/td>\n<td> \t\t\t\tyank lines into buffer<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \tWords, Sentences, Paragraphs<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>w<\/b><\/td>\n<td> \t\t\t\tword forward<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>b<\/b><\/td>\n<td> \t\t\t\tword backward<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>e<\/b><\/td>\n<td> \t\t\t\tend of word<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>)<\/b><\/td>\n<td> \t\t\t\tto next sentence break<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>}<\/b><\/td>\n<td> \t\t\t\tto next paragraph break<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>(<\/b><\/td>\n<td> \t\t\t\tto previous sentence break<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>{<\/b><\/td>\n<td> \t\t\t\tto previous paragraph break<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>W<\/b><\/td>\n<td> \t\t\t\tto next blank-delimited word<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>B<\/b><\/td>\n<td> \t\t\t\tto previous blank-delimited word<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>E<\/b><\/td>\n<td> \t\t\t\tto end of blank-delimited word<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \tYank to Buffer, and Paste from Buffer<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>p<\/b><\/td>\n<td> \t\t\t\tpaste after cursor<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>P<\/b><\/td>\n<td> \t\t\t\tpaste before cursor<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>&quot;<\/b><i>x<\/i><b>p<\/b><\/td>\n<td> \t\t\t\tpaste from buffer <i>x<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>&quot;<\/b><i>x<\/i><b>y<\/b><\/td>\n<td> \t\t\t\tyank into buffer <i>x<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>&quot;<\/b><i>x<\/i><b>d<\/b><\/td>\n<td> \t\t\t\tdelete into buffer <i>x<\/i><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \tUndo, Redo, Retrieve<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>u<\/b><\/td>\n<td> \t\t\t\tundo last change<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>U<\/b><\/td>\n<td> \t\t\t\trestore current line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>.<\/b><\/td>\n<td> \t\t\t\trepeat last change<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>&quot;<\/b><i>d<\/i><b>p<\/b><\/td>\n<td> \t\t\t\tretrieve <i>d<\/i>th last delete<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \tMarking and Returning<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>&#8220;<\/b><\/td>\n<td> \t\t\t\tgo to previous location<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>&#39;&#39;<\/b><\/td>\n<td> \t\t\t\tgo to previous location, at first non-whitespace in line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>m<\/b><i>x<\/i><\/td>\n<td> \t\t\t\tMark position with letter <i>x<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>`<\/b><i>x<\/i><\/td>\n<td> \t\t\t\tmove to the position marked <i>x<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>&#39;<\/b><i>x<\/i><\/td>\n<td> \t\t\t\tmove to the position marked <i>x<\/i>, at the first non-whitespace character in the line<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \tMiscellaneous Operations<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>C<\/b><\/td>\n<td> \t\t\t\tchange rest of line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>D<\/b><\/td>\n<td> \t\t\t\tdelete rest of line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>s<\/b><\/td>\n<td> \t\t\t\tsubstitute characters<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>S<\/b><\/td>\n<td> \t\t\t\tsubstitute lines<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>J<\/b><\/td>\n<td> \t\t\t\tjoin lines<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>x<\/b><\/td>\n<td> \t\t\t\tdelete a single character<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>X<\/b><\/td>\n<td> \t\t\t\tdelete a single character <i>before<\/i> the cursor<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>Y<\/b><\/td>\n<td> \t\t\t\tyank a line; same as <b>yy<\/b><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \tAdjusting the Screen<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^L<\/b><\/td>\n<td> \t\t\t\tclear and redraw<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>z<\/b>(Enter)<\/td>\n<td> \t\t\t\tredraw screen with current line at top<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>z-<\/b><\/td>\n<td> \t\t\t\tredraw screen with current line at bottom<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>z.<\/b><\/td>\n<td> \t\t\t\tredraw screen with current line at center<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>zz<\/b><\/td>\n<td> \t\t\t\tsame as <b>z.<\/b><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^E<\/b><\/td>\n<td> \t\t\t\tscroll window down one line (but don&#39;t move cursor)<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>^Y<\/b><\/td>\n<td> \t\t\t\tscroll window up one line (but don&#39;t move cursor)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \tUseful Command Combinations<\/h2>\n<table class=\"mtable\">\n<tbody>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>dw<\/b><\/td>\n<td> \t\t\t\tdelete a word<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>de<\/b><\/td>\n<td> \t\t\t\tdelete a word, leaving any of its punctuation intact<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>dd<\/b><\/td>\n<td> \t\t\t\tdelete a line<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>3dd<\/b><\/td>\n<td> \t\t\t\tdelete 3 lines (for example)<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>cw<\/b><i>new<\/i><\/td>\n<td> \t\t\t\tchange word to <i>new<\/i><\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>eas<\/b><\/td>\n<td> \t\t\t\tpluralize a word (stick an s at the end of it)<\/td>\n<\/tr>\n<tr class=\"tcw\">\n<td> \t\t\t\t<b>xp<\/b><\/td>\n<td> \t\t\t\ttranspose two characters<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2> \t<a name=\"03\"><\/a>Examples<\/h2>\n<pre class=\"tcy\">vi myfile.txt<\/pre>\n<p class=\"tab\"> \tEdits the file <b>myfile.txt<\/b>.<\/p>\n<p class=\"tab\"> \t&nbsp;<\/p>\n<p class=\"tab\"> \t&nbsp;<\/p>\n<\/article>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Linux and Unix vi command Quick links About Vi Syntax Using Vi Moving Around in Vi Making Simple Changes Rearranging and Duplicating Text High Level Commands Special Topics Technical Details Quick Reference Examples Related commands Linux and Unix main page About vi Originally developed by William Joy in the late 1970s, vi (pronounced &quot;vee-eye&quot;) is&#8230;<\/p>\n","protected":false},"author":1,"featured_media":258,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-259","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/posts\/259","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=259"}],"version-history":[{"count":1,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/posts\/259\/revisions"}],"predecessor-version":[{"id":382,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/posts\/259\/revisions\/382"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/media\/258"}],"wp:attachment":[{"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}