1 / 20

Visual ( vi ) Editor

7. CHAPTER. Visual ( vi ) Editor. Objectives Upon completion of this module, you should be able to: Define the three modes of operation used by the vi editor. Start the vi editor. Position and move the cursor in the vi editor. Switch between vi modes. Create and delete text.

enoch
Télécharger la présentation

Visual ( vi ) Editor

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 7 CHAPTER Visual (vi) Editor • Objectives • Upon completion of this module, you should be able to: • Define the three modes of operation used by the vi editor. • Start the vi editor. • Position and move the cursor in the vi editor. • Switch between vi modes. • Create and delete text. • Copy or move text. • Set vi options. • Perform search and replace functions within the vi editor. • Exit the vi editor.

  2. Introducing vi • The visual display (vi) editor is an interactive editor used to create or modify text files. • All text editing with the vi editor takes place in a buffer. • Changes can either be written to the disk or be discard. • For those who intend on becoming system administrators, it is important to know how to use the vi editor. • You need to know how to use the vi editor in case the windowing system is now available. • The vi editor is also the only text editor that can be used to edit certain system files without changing the file’s permissions. Figure 7-1 Terminal Window – Initial vi Display

  3. vi Modes • The vi editor is a command-line editor that has three basic modes of operation: • Command mode • Edit mode • Last line mode

  4. Command Mode • This is the default mode for the vi editor. • In this mode, you can enter commands to delete, change, copy, and move text; position the cursor; search for text strings; or exit the vi editor.

  5. Edit Mode • In this mode, you can enter text into a file. • To instruct the vi editor to enter edit mode, enter one of the following three commands: • i (insert) • o (open) • a (append)

  6. Last Line Mode • While in command mode, you can use advanced editing commands by typing a colon (:), which places you at the bottom line of the screen. • This is called last line mode. • However, all commands are initiated from command mode.

  7. Switching Modes • By typing i, o, or a command, the vi editor leaves the default command mode and enters edit mode. • In edit mode, text is not interpreted as commands by the vi editor. Now, everything you type is entered into the file as text. • When you have finished entering text in the file, you can return the vi editor to command mode by pressing the Escape key. • When you are back in command mode, you can then save the file an quit the vi editor. • For example: • Type vifinename to create a file. • Type the i command to insert text. • Press the Escape key to return to command mode. • Type :wq to write and save the file and exit thevi editor.

  8. Invoking the vi Editor • To create a new file, invoke the vi editor with a new file name by typing commands to create, edit, or view a file. • Command Format • vi option(s) filename • view filename • Input commands • To insert or append text, use the commands in Table 7-1. Table 7-1 Note The vi editor is case sensitive, so use the specified case when using these cursor-input commands.

  9. Table 7-2 Command Meaning h, , or Back Space Moves left one character j or Moves down one line k or Moves up one line l, , or Space bar Moves right ( forward ) one character w Moves forward one word b Moves back one word e Moves to the end of the current word $ Moves to the end of the line 0 (zero) Moves to the beginning of the line ^ Moves to the first non-whitespace character on the line Return Moves down to the beginning of the next line Control-F Pages forward one screen Control-D Scrolls down one-half screen Control-B Pages back one screen Control-U Scrolls up one-half screen Control-L Refreshes the screen Positioning Commands • Table 7-2 shows the key sequences that control cursor movement in the vi editor.

  10. Editing Commands • Deleting Text • To delete text, use the options in table 7-3. Table 7-3

  11. Undoing, Repeating, and Changing Text Commands • To change text, undo a change, or repeat an edit function, use the commands in Table 7-4. • Many of these commands change the vi editor to edit mode. • To return to command mode, press the Escape key.

  12. Edit Commands for the vi Editor -1 Table 7-4

  13. Edit Commands for the vi Editor -2 Table 7-4 ( Continued )

  14. Edit Commands for the vi Editor -3 • To search and replace text, use the options in table 7-5. Table 7-5

  15. Copying and Pasting Text • The copy commands write the copied text into a temporary buffer. The paste commands read the text from the temporary buffer and write the text into the current document at the specified location. • To copy and paste text, use the options in table 7-6 Table 7-6 Note Both delete and yank write to a buffer. When yanking, deleting, and pasting, the put commands insert the text differently depending on whether you are pasting words or lines.

  16. Saving and Quitting Files Table 7-7

  17. Customizing Your vi Session • The vi editor includes options for customizing edit sessions, such as: • Displaying line numbers • Displaying invisible characters, such as tab and end-of-line characters • Use the set command in command mode to control these options, as shown in table 7-8. • You can also place these options in a file you create in you home directory called .exrc. • The set options are placed in this file, without the preceding colon, one command to a line. • After the .exrc file has been created, it is read by the system each time you open a vi session.

  18. Edit Session Customization Commands Table 7-8

  19. Positioning & Refreshing Command • To find a particular line, use the options in table 7-9. Table 7-9 • To clear the screen or insert files, use the option in table 7-10. Table 7-10

  20. $ vi demo Command Mode : / ? i a o Return Escape Last Line Mode Edit Mode Chapter7 exercise: Using the vi Editor • Tasks • Complete the following steps: • In your home directory, there should be a file called tutor.vi. Make sure you are currently in your home directory, and then open this file with the command: This opens a vi tutorial file. • Complete the lessons outlined in this tutorial. $ vi tutor.vi

More Related