home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / Documents / Others / viCourse+ / vi-cours.txt < prev    next >
Text File  |  1992-12-20  |  18KB  |  563 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.                                  Gregg Wonderly
  10.                              Mathematics Department
  11.                             Oklahoma State University
  12.  
  13.                                    12-NOV-1987
  14.  
  15.         1  Introduction
  16.  
  17.  
  18.         Editing text consists of only  a  few  basic  operations.   These
  19.         operations  can  be  summarized  by  generalizations  to  be just
  20.         insertions  and  deletions.   Most  text  editors  provide   text
  21.         insertion  capabilities  by allowing the user to just type.  Text
  22.         deletions are then accomplished by the use of certain  non-typing
  23.         keystrokes which are not allowed to insert text into the document
  24.         being edited.   These  types  of  editors  are  typically  called
  25.         modeless editors, because they apparently have no special mode to
  26.         distinguish between inserting and deleting text  (just  different
  27.         keystrokes).
  28.  
  29.         VI is not one of these types of editors.  VI is a  moded  editor,
  30.         as  it  has  a specific mode for inserting text, and another mode
  31.         (which makes use of the normal typing keys) which allows deleting
  32.         text.  Like anything different, it can take some time to get used
  33.         to this type of editing.  There are  some  real  benefits  to  be
  34.         gained  from  it.   Some  are  quite significant, an others while
  35.         perhaps  not  terribly  important,  are  deeply  rooted  in   the
  36.         progression of computers and terminals.
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.                                           1
  56.  
  57.                                      Introduction
  58.  
  59.  
  60.                                            CONTENTS
  61.  
  62.                 1       Introduction . . . . . . . . . . . . . . . . . . . . 1
  63.                 2       Learning the power of VI . . . . . . . . . . . . . . 3
  64.                 2.1       Inserting Text . . . . . . . . . . . . . . . . . . 4
  65.                 2.2       Deleting Copying and Changing  . . . . . . . . . . 5
  66.                 3       Single Key Movements . . . . . . . . . . . . . . . . 5
  67.                 3.1       Sample Use of the Single Key Movements . . . . . . 7
  68.                 3.2       Common Keystroke Combinations  . . . . . . . . . . 8
  69.                 3.3       Glossary . . . . . . . . . . . . . . . . . . . . . 9
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.                                           2
  113.  
  114.                                      Introduction
  115.  
  116.  
  117.              There has never really  been  a  standard  terminal  with  a
  118.         standard  layout  of keys (other than the QWERTY keyboard).  This
  119.         presents a real problem when you have several different types  of
  120.         terminals  that  you  use.   VI  attempts to solve the problem of
  121.         dealing with different keyboards by making it unnecessary to  use
  122.         anything but the QWERTY keyboard.
  123.  
  124.         This is advantageous when a particular site has  different  types
  125.         of  terminals.  This was the case at the University of California
  126.         at Berkeley when Bill Joy first wrote  VI.   Bill  was  presented
  127.         with  the  task  of  writing  a  full screen editor that would be
  128.         usable on all of  the  terminals  that  had  been  given  to  the
  129.         Computer  Science  folks there.  Out of this came two things, VI,
  130.         and more importantly, curses which  allows  terminal  independent
  131.         access to windowing capabilities.  Quite an accomplishment Bill!
  132.  
  133.  
  134.         2  Learning the power of VI
  135.  
  136.  
  137.         With that out of the way, lets move on to learning VI.  There are
  138.         two  modes  of  operation  that  the  VI editor can be in.  It is
  139.         either in command mode, or in insert mode.  When you first  enter
  140.         the  editor, it is in command mode.  One of the very first things
  141.         to learn about VI is, when you are not sure, bang on  the  escape
  142.         key a few times until you hear a beep.  The escape key is used to
  143.         change modes from text insert mode to editing  command  mode,  so
  144.         banging  on  it  a few times will always get you to command mode,
  145.         when you are in insert mode.
  146.  
  147.         VI allows you to perform many tasks  with  very  few  keystrokes.
  148.         This is good for those who get tired of typing lots of keystrokes
  149.         to perform editing operations.  This can be  bad  for  those  who
  150.         make  lots  of  typing  mistakes.   I say "can be bad" because VI
  151.         allows you to recover from typing mistakes by undoing  operations
  152.         that  insert/delete  text  into/from a document.  Operations that
  153.         alter a document  are  explicit  in  VI.   There  is  a  definite
  154.         starting point, and a definite ending point.  This is what allows
  155.         VI to "know" how to undo what you last did.  As long as you  only
  156.         make one mistake at a time, you can undo that mistake by typing a
  157.         'u' (for undo) keystroke while in command mode.  This is  perhaps
  158.         the most appreciated feature of VI.  There is another key stroke,
  159.         'U', which also allows you to undo mistakes.  It  will  undo  all
  160.         changes  made  to  the current line, providing the cursor has not
  161.         left that line since the changes were made.
  162.  
  163.  
  164.                                           3
  165.                           Learning to use VI 
  166.                                Learning the power of VI
  167.  
  168.  
  169.         2.1  Inserting Text
  170.  
  171.  
  172.         VI  incorporates  several  methods  of  inserting  text  into   a
  173.         document.   There  are  three different methods you can use while
  174.         you are in command mode.  Typing an 'i'  (for  insert)  keystroke
  175.         allows  you  to  insert characters into the document at the point
  176.         that the cursor is positioned.  As mentioned  above,  typing  the
  177.         <ESC>  (or  escape) keystroke allows you to exit (or escape) from
  178.         insert mode.  Due to the many different places that a person  may
  179.         want to insert text at, there are keystrokes other than 'i', that
  180.         place the editor directly into  insert  mode,  after  moving  the
  181.         cursor.  These are outlined below.
  182.  
  183.         Insert commands
  184.              'i'         Allows you to insert at the current cursor
  185.                          position.
  186.  
  187.              'I'         Allows you to begin inserting at the beginning
  188.                          of the line, no matter where the cursor is
  189.                          positioned on the current line.
  190.  
  191.         Open commands
  192.              'o'         Allows you to begin inserting on a new, empty
  193.                          line that is opened for you, below the current
  194.                          line.
  195.  
  196.              'O'         Allows you to begin inserting on a new, empty
  197.                          line that is opened for you, above the current
  198.                          line.
  199.  
  200.         Append commands
  201.              'a'         Allows you to begin inserting after the
  202.                          character (append) that the cursor is
  203.                          positioned on.
  204.  
  205.              'A'         Allows you to begin inserting at the end of the
  206.                          current line, no matter where the cursor is
  207.                          positioned on that line.
  208.  
  209.         There are other commands that place you in  insert  mode.   These
  210.         commands are used to perform substitutions of text.  That is, the
  211.         deletion of old text and the insertion of  new  text,  all  in  a
  212.         single  operation.   These  commands will be discussed further on
  213.         because the are actually macros of the change command.
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.                                           4
  222.                           Learning to use VI 
  223.                                Learning the power of VI
  224.  
  225.  
  226.         2.2  Deleting Copying and Changing
  227.  
  228.  
  229.         The next three operations  we  will  discuss  will  be  deleting,
  230.         copying,  and  changing.   These three will be discussed together
  231.         because the methods of describing the text  that  these  commands
  232.         operate on is identical.
  233.  
  234.         There are well over 30 different ways that you  can  tell  VI  to
  235.         move  the  cursor  to  a  new  location  in  the document.  These
  236.         movements can also be used to describe sections of  the  document
  237.         that you wish to perform operations on.  Typically, you will type
  238.         a single keystroke which describes the type of operation you wish
  239.         to perform, e.g.  'd' to delete.  There are several commands that
  240.         allow you to use a normal movement command to describe a  portion
  241.         of  the  document  you  are editing.  These commands are outlined
  242.         below.
  243.  
  244.              'd'         Delete text.
  245.              'y'         Copy text (that is, yank it into a holding
  246.                          area for later use).
  247.              'c'         Change text from one thing to another, which
  248.                          you will type.
  249.              '!'         Filter text through a program.
  250.              '<'         Shift a region of text to the left.
  251.              '>'         Shift a region of text to the right.
  252.  
  253.                                     Figure 1.
  254.  
  255.         The first three are the basic text operations that allow  you  to
  256.         alter  a  document  by deleting, copying and changing the text in
  257.         it.  The last three are more advanced operations that are  useful
  258.         and handy to have.
  259.  
  260.         3  Single Key Movements
  261.  
  262.  
  263.         Following one of the commands identifying  keystrokes  listed  in
  264.         Figure  1,  you  must  tell  VI  what  portion of the document to
  265.         perform the operation on.  This is done  by  typing  a  keystroke
  266.         that  indicates  a  movement command.  Most of these are outlined
  267.         below.  The more complicated movements will  be  described  later
  268.         on.  Each character is surrounded by single quotes.
  269.  
  270.              '`'         Move the cursor to a previously marked location
  271.                          in the document.
  272.  
  273.              '$'         Move the cursor to the end of the current line,
  274.                          or if a count is specified, to the end of the
  275.                          (n-1)th line below the current line.
  276.  
  277.  
  278.                                           5
  279.                           Learning to use VI 
  280.                                  Single Key Movements
  281.  
  282.  
  283.              '%'         Move the cursor to the matching parenthesis,
  284.                          bracket or brace.
  285.  
  286.              '^'         Move the cursor to the beginning of the line.
  287.  
  288.              '('         Move the cursor to the beginning of the previous
  289.                          sentence.
  290.  
  291.              ')'         Move the cursor to the beginning of the next
  292.                          sentence.
  293.  
  294.              '-'         Move the cursor to the first non-blank character
  295.                          on the previous line.
  296.  
  297.              '+'         Move the cursor to the first non-blank character
  298.                          on the next line.
  299.  
  300.              'w'         Move the cursor to the beginning of the next
  301.                          type of character, where types are alphanumeric,
  302.                          punctuation, and spaces (words of this type are
  303.                          commonly refered to as logical words).
  304.  
  305.              'W'         Move the cursor to the next space separated
  306.                          word (words of this type are commonly refered
  307.                          to as physical words).
  308.  
  309.              'e'         Move the cursor to the end of the current type
  310.                          of character.
  311.  
  312.              'E'         Move the cursor to the end of non blank
  313.                          characters.
  314.  
  315.              't'         Move the cursor to the the character preceeding
  316.                          that cooresponding to the next character typed,
  317.                          moving forward.
  318.  
  319.              'T'         Same as 't' but movement is backward.
  320.  
  321.              '[['        Move the cursor to the beginning of the current
  322.                          section, where a section is outlined later.
  323.  
  324.              ']]'        Move the cursor to the beginning of the next
  325.                          section, where a section is outlined later.
  326.  
  327.              '{'         Move the cursor to the beginning of the current
  328.                          paragraph.
  329.  
  330.              '}'         Move the cursor to the beginning of the next
  331.                          paragraph.
  332.  
  333.              'f'         Move the cursor to the next occurance (find
  334.  
  335.                                           6
  336.                           Learning to use VI 
  337.                                  Single Key Movements
  338.  
  339.  
  340.                          character) of the character corresponding to
  341.                          the next keystroke typed, moving backwards.
  342.  
  343.              'F'         Same as 'f' but movement is backwards.
  344.  
  345.              'G'         Move the cursor to the line specified by the
  346.                          numeric keys typed preceeding this key, or to
  347.                          the end of the document if none were typed.
  348.  
  349.              'h'         Move the cursor to the left one character.
  350.  
  351.              'H'         Move the cursor to the top of the Screen, as
  352.                          opposed to the top of the document which may
  353.                          not be the same.
  354.  
  355.              'j'         Move the cursor to the same column of the line
  356.                          below the current line.
  357.  
  358.              'k'         Move the cursor to the same column of the line
  359.                          preceeding the current line.         
  360.  
  361.              'l'         Move the cursor to the right one character.         
  362.  
  363.              'L'         Move the cursor to the last line on the screen,
  364.                          as opposed to the last line of the document
  365.                          which may or may not be the same.
  366.  
  367.              ';'         Repeat the last 't' or 'f' command, or the last
  368.                          'F' or 'T' command but in the forward direction.
  369.  
  370.              '''         Move the cursor to the first non-space character
  371.                          of the line that the the indicated marker is set
  372.                          on.
  373.  
  374.         You probably will not adopt the immediate use  of  all  of  these
  375.         movements,  but  it  is  possible to gain proficency in their use
  376.         only by using them.
  377.  
  378.         3.1  Sample Use of the Single Key Movements
  379.  
  380.  
  381.         Perhaps some sample uses of these movements will make their use a
  382.         little more obvious.  Typically, a VI manual resolves to give the
  383.         reader a list of the most common keystroke combinations,  without
  384.         trying  to  describe  the  real  reasoning behind the keystrokes.
  385.         This is part of the reason that  VI  seems  so  foreign  to  some
  386.         people,   they   never  discover  the  relationship  of  all  the
  387.         keystrokes to one another.  However, since I  have  outlined  the
  388.         basic relationship of the keystrokes, I feel that I can provide a
  389.         similar chart without causing any confusion.   The  notation  <n>
  390.         means that you may type one or more of the keys, 0-9, to indicate
  391.  
  392.                                           7
  393.                           Learning to use VI 
  394.                                  Single Key Movements
  395.  
  396.  
  397.         a repeat count that will  cause  the  movement  indicated  to  be
  398.         performed  the  indicated number of times.  e.g.  5dw will delete
  399.         five logical words, 35dd will delete thirty five lines.
  400.  
  401.         3.2  Common Keystroke Combinations
  402.  
  403.  
  404.              <n>d$   Delete (including the current character),
  405.                      to the end of the (n-1)th line.
  406.              <n>d^   Delete (excluding the current character),
  407.                      to the beginning of the (n-1)th line.
  408.              <n>dE   Delete to the end of physical words
  409.                      (or TO the next space or tab character).
  410.              <n>de   Delete to the end of logical word.
  411.              <n>dd   Delete lines.
  412.              dG      Delete from the current line to the end
  413.                      of the document.
  414.              dH      Delete from the current line to the line
  415.                      shown at the top of the display, inclusive.
  416.              <n>dh   Delete n characters to the left of the
  417.                      cursor, 'X' is equivalent to this.
  418.              <n>dj   Delete the current line, and the n lines
  419.                      below it.
  420.              <n>dk   Delete the current line, and the n lines
  421.                      above it.
  422.              <n>dl   Delete n characters to the right of the
  423.                      cursor, including the one under it,
  424.                      'x' is equivalent to this.
  425.              <n>db   Delete back to the beginning of the
  426.                      nth previous logical word.
  427.              <n>dB   Delete back to the beginning of the
  428.                      nth previous physical word.
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.                                           8
  449.              3.3  Glossary
  450.  
  451.  
  452.                   logical word    A word that is made up of characters
  453.                                   of a common class.  The classes are
  454.                                   alphabetic/numeric and '_',
  455.                                   punctuation, and space or tab.
  456.  
  457.                   Physical word   A word that is made up of non-space
  458.                                   and non-tab characters.  Or put
  459.                                   another way, words made up of
  460.                                   printable characters.
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.                                           9
  506.                                         INDEX
  507.  
  508.  
  509.  
  510.         Deletion, 1                         Insertion, 1
  511.                                             Introduction, 1
  512.         Escape, 3
  513.          
  514.         Glossary, 9                         Undo, 3
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.                                        Index-1
  563. ons  the nare in.  Th.  Th.ludkey ikey ik  c the nare in.  Th.  Th.ludkey ikey ik  c the nare in.  Th.  Th.ludkey ikey ik  c the nare in.  Th.  Th.ludkey ikey ik  c the nare in.  Th.  Th.ludkey ikey ik  c the nare in.  Th.  Th.ludkey ikey ik  c the nare in.  Th.  Th.ludkey ikey ik  c the nare in