Presentation is loading. Please wait.

Presentation is loading. Please wait.

Agenda Using vi Editor Starting vi Session Command / Input Modes Entering Text Editing Text Saving Edited File Aborting Editing Session.

Similar presentations


Presentation on theme: "Agenda Using vi Editor Starting vi Session Command / Input Modes Entering Text Editing Text Saving Edited File Aborting Editing Session."— Presentation transcript:

1 Agenda Using vi Editor Starting vi Session Command / Input Modes Entering Text Editing Text Saving Edited File Aborting Editing Session

2 vi (Visual) Editor vi is a powerful, interactive, visually- oriented text editor Features: flexibility in performing various tasks. possible to recover file edited by vi in the event of a “system crash”. Custom-designed for programmers.

3 Starting vi Session The most common way to start an editing session with vi: Enter vi filename (if filename exists, it will be edited. If it doesn’t exist, then it will be created when the file is saved).

4 Modes There are two operational modes while using the vi editor: Command Mode (default mode when starting!) Mode to allow user to give commands such as to delete text, search for strings, search & replace, save changes, abort editing session without saving changes and exit the vi editor. Input Mode Input Mode allows user to enter or edit text. This is what makes vi difficult for most people first learning vi!

5 Input Mode While in command mode, you can issue the following commands to input text: i – insert to left of cursor I – insert at beginning of line o – insert (open) line below current line 0 – insert (open) line above current line a - insert (append) to right of cursor A - insert (append) at end of current line r - replace character R – overwrite text NOTE: 1.To enter command mode while in input mode, press the key. 2. While in input mode, the input mode indicator should appear as INPUT on the bottom of the vi screen. If this indicator does not appear when in input mode, then type: :set showmode

6 Input Mode Type in your text, but it is recommended to press before the end of the line (i.e. do not use word-wrap). Also, do not use to end a line. Tilde “~” characters below text represent end of file. Error Correction (As you type): CTRL-hDelete a letter CTRL-wDelete a word CTRL-uDelete a line Do these key-combinations look familiar?

7 Editing Text You can move around to text in the screen with the arrow keys while you are in insert mode. For more advanced editing, you can return to Command Mode and use appropriate editing commands. While in command mode, you can move throughout file by using arrow keys and letters h (left), j (down), k (up), and l (right).

8 Editing Text Other movement keys within command mode: w – move forward by one word W – move forward by space-delimited word 0 (zero) – move to beginning of line $ - move to end of line ) - move forward to next sentence ( - move backward to previous sentence } - move forward to next code block { - move backward to previous code block - move forward one screen - move backward one screen G – move to last line in file # G – move to line number in file H – move to top of current screen M – move to middle of current screen L - move to bottom of current screen /reg-exp – move to next matching location TIP: Placing a number before the movement key will repeat the movement by that number

9 Editing Commands (Within Command Mode) The major Text Editing Commands are: d – Delete c – Change y – Yank (copy) When combined with movement keys, the vi editor becomes an effective editing tool. eg. d4W(Delete the next four space-delimited words) c$(Change from the cursor to the end of the line) y$(Copy from cursor to the end of the line) d34d(Delete current line and following 33 lines) Pressing the period “.” in command mode will repeat the most recent edit!

10 Saving Edited File When you create or edit a file using vi, all work performed during vi session is stored in a Work Buffer (temporary storage) until the work is saved. When saving, changes in the work buffer are placed in a new file if creating a new file, or changes in work buffer modify existing (previously created) file.

11 Saving Edited File To save your vi session, you must make sure you are in command mode by pressing To save your changes and exit, enter ZZ (i.e. two capital z’s) You can also save without exiting by entering :w

12 Aborting Editing Session If you make a huge mistake in your editing session (that undo cannot solve), you can abort your session without modifying the contents of of the existing file. To abort the current editing session, press :q!


Download ppt "Agenda Using vi Editor Starting vi Session Command / Input Modes Entering Text Editing Text Saving Edited File Aborting Editing Session."

Similar presentations


Ads by Google