Next 7.A.3: Saving and Exiting  Up 7: Editing Files  Prev 7.A.1: Moving in vi  Contents

Basic

§ 7.A.2: Making Changes in vi


Now that you've opened a file with vi, let's edit it. First notice that at the end of the file there is a line with NAME and DATE in it. Try changing these to your name and today's date.

One way to change text in vi is to: delete the old text, and then, insert the new text. (Some people find it easier to insert the new text before deleting the old.)

  1. Move your cursor to the text you wish to change.
  2. Because you are in command mode, you must change to insert mode before entering text.
  3. Change to insert mode by typing i.
  4. Now type in your name and today's date.
  5. Before you can delete the old name and date, you need to exit insert mode.
  6. Exit insert mode by pressing the [Escape] key.
  7. Now position the cursor over the leftmost characters you wish to delete.
  8. The delete commands are:
    x
    delete a single character
    dw
    delete a single word
    dd
    delete an entire line
  9. If you make any mistakes, the undo commands are
    u
    undo the last change
    U
    undo all changes on this line

Other useful commands for editing are:

You will notice nothing appears to happen when you do a yank. Yet if you move the cursor to where you want to place the copied text and issue the put command P, the text get put there.

Try these commands a few times with the sample file; it takes some getting used to, but it can be real fast. We will finish our brief introduction to vi with saving your work and exiting vi.


Next 7.A.3: Saving and Exiting  Up 7: Editing Files  Prev 7.A.1: Moving in vi  Contents

Comments and questions to CP-unix@physics.orst.edu.