Operating System Lab Manual CS 2254
vi EDITOR COMMANDS
EX.NO :1.b
DATE :
AIM:                                                                      UNIX.
                 To study the various commands operated in vi editor in
 DESCRIPTION :
               The Vi editor is a visual editor used to create and edit text, files, documents and
                                                                                  to add, delete or
programs. It displays the content of files on the screen and allows auser
change part of text. There are three modes available in the Vi editor, they are
                 1.Command mode
                 2.Input (or) insert mode.
 Starting Vi:
                 The Vi editor is invoked by giving the following commands in UNIX prompt.
        Svntax:           $vi<filename> (or)
                         $vi
        This command would opena display screen with 25 lines and with tilt (~) symbol at the
start of each line. The first syntax would save the file in the filename mentioned and for the
next the filename must be mentioned at the end.
        Options:
               l.vi+n<filename>- thiswould point at the nth line (cursor pos).
              2.vi -n <filename>- This command is tomake the file to read only to change
              from one mode to another press escape key.
 INSERTING AND REPLACING COMMANDS:
       To move editor from command node to edit mode, you have to press the <ESC> key.
For inserting and replacing the following commands are used.
  1.ESC a Command:
        This command is used to move the edit mode and start to append after the current
 character.
         Syntax :         <BSC>a
  2.ESC A COMMAND :
       This command is also used to append the file , but this command append at the end of
 current line.
          Syntax :        <ESC> A
 @www.getitcse.tk                                                                            Page 10
                                           Manual CS                     2254
                       OperatingSystem Lab
3.ESC i Command:
                             insert the text before the current cursor position.
     This command is used to
       Syntax :    <ESC>i
4.ESC ICommand :                                       of the current      line.
        Thiscommand is used to insert at the beginning
        Syntax :   <ESC> I
 5.ESC o Command:
                                                                      allow insertion of
         This command is insert a blank line below the current line &
contents.
         Syntax :       <ESC>0
 6.ESC O Command:
      This command is used to insert a blank line above &allow insertion of contents.
         Svntax :        <ESC> O
 7.ESC r Command:
        This command is to replace the particular character with the given characters.
         Svntax :   <ESC> rx                 Where x isthe new character.
 8.ESC R Command :
       This command is used to replace the particular text witha given text.
            Syntax :     <ESC> R text
 9.<ESC>s Command :
      This command replaces a single character with a group of character
         Syntax :       <ESC> s
10.<ESC>SCommand:
        This command is used to replace a current line with group of characters.
         Syntax :       <ESC> S
 CURSOR MOVEMENT IN vi:
1<ESC>h:
     This      command is used to move to the previous character typed. It is used
left of the text. It can also used to move character by character                  to moye to
                                                                  (or) a number of characters.
        Syntax :        <ESC>h- to move one character to left.
                        <ESC> nh - tomove 'n' character to left.
2.<ESC>l:
        This command is used to move to the right of the cursor (ie) to the next character It can
also be used to move the cursor for a number of character.
        Syntax :         <ESC>1-single character to right.
                        <ESC> nl -n' characters to right.
@www.getitcse.tk                                                                        Page 11
                     Operating System Lab Manual CS 2254
3.<ESC> i:
      This command is used to move down a single line or a number of lines.
      Syntax :
             <ESC>j-singledown movement.
               <ESC> nj      n times down movement.
4.<ESC> k:                                                   number of lines.
      This command is used to move up a single line or a
       Syntax :
             <ESC> k- single line above.
             <ESC> nk n' lines above.
5.ENTER (OR) NENTER:                                    of next lines or a group of lines
      This command will move the cursor to the starting
mentioned.
       Syntax:                       <ESC>n enter.
               <ESC> enter
 6.<ESC>+ Command :
                                           beginning of the next line.
       This command is used to move to the
        Svntax :                  <ESC> n+
               <ESC>t
 7<ESC>-Command :
                                               beginning of the previous line.
        This conmmand is used to move to the
        Svntax :
               <ESC>                  <ESC> n
  8.<ESC> 0:                                               of the same current   line.
        This command willbring the cursor to the beginning
         Syntax :
                <ESC> 0
  9.<ESC> S:
        This command will bring the cursor to the end of the current line.
         Syntax :
                <ESC> $
 10,<ESC>^;
        This command is used to move to first character of first lines,
         Syntax :
                <ESC> A
   11.<ESC> b Command :
          This command is used to move back to the previous word (or) a mumber of words.
          Syntax :
                 <ESC> b              <ESC>nb
  @www.getitcse.tk                                                                       Page 12
                        Operating System Lab Manual CS 2254
   12,<ESC>e Command:dalenthanobstot obsn
         This command is used to move towards and replace the cursor at last character of the
  word (or) no of words.
             Syntax :
                    <ESC> e               <ESC>ne
  13.<ESC>w   Command:sl sloaiz ogu svoro bozuibusnreos
       This command is used to move forward by a single word or a group of words.
                                                      ovodr onil olutz
             Syntax:                     <ESC> nwodh ol
                  <ESC> W
  DELETING THE TEXT FROM Vi:
  1.<ESC>r Command :
                                                                  this command is used.
  ou To delete a character to right of current cursor positions ,
       Syntax :
                  <ESC> x                        <ESC> nx
 2.<ESC>X Command :
                                                                          command is used.
         To delete a character to left of current cursor positions , this
         Syntax
                  <ESC> X                        <ESC> nX
  3.<ESC> dw Command :
                                                                       right of current cursor
         This command is to delete a single word or number of words to
 position.
                  <ESC> dw                       <ESC> ndw
 4.db Command  : is to delete a single word to the left of the current cursor position.
       This command
                  <ESC> db                      <ESC> ndb
 5.<ESC> dd Command :
        This command is used to delete the current line (or) a number of line below the current
line.
         Syntax :
                                                                     S. <EScy
                  <ESC> dd                      <ESC> ndd
                                                                                Sk agein to save
 6.<ESC> dS Command :                                                     Sytax! <Esc:q
        This command is used to delete the text from current cursor position tolast character of
current line.
        Syntax :        <ESC> d$
SAVING AND QUITING FROM vi:
 1<ESC> wCommand
              :ovonpiot do                                           b,t
         Tosave the given text present in the file.
         Syntax :       <ESC>:w                                          d023
                                                                                         geven text
@www.getitcse.tk                                                            taaiiwPage 13
3. <EscywY
                                             4sc
                                              Conmand                same as         waone qut
                                                Synta:               <Esc