2.1. vi Commands

vi has two modes: command mode and insert mode. As soon as you enter a file, you are in command mode, and the editor is waiting for you to enter a command. Commands enable you to move anywhere in the file, to perform edits, or to enter insert mode to add new text. Commands can also be given to exit the file (saving or ignoring your edits) in order to return to the UNIX prompt.

You can think of the different modes as representing two different keyboards. In insert mode, your keyboard functions like a typewriter. In command mode, each key has a new meaning or initiates some instruction.

There are several ways to tell vi that you want to begin insert mode. One of the most common is to press i. The i doesn't appear on the screen, but after you press it, whatever you type will appear on the screen and will be entered into the buffer. The cursor marks the current insertion point. To tell vi that you want to stop inserting text, press ESC. Pressing ESC moves the cursor back one space (so that it is on the last character you typed) and returns vi to command mode.

For example, suppose you have opened a new file and want to insert the word "introduction". If you type the keystrokes iintroduction, what appears on the screen is:

introduction

When you open a new file, vi starts in command mode and interprets the first keystroke (i) as the insert command. All keystrokes made after the insert command are considered text until you press ESC. If you need to correct a mistake while in insert mode, backspace and type over the error. Depending on the type of terminal you are using, backspacing may erase what you've previously typed or may just back up over it. In either case, whatever you back up over will be deleted. Note that you can't use the backspace key to back up beyond the point where you entered insert mode.

vi has an option that lets you define a right margin and provides a carriage return automatically when you reach it. For right now, while you are inserting text, press RETURN to break the lines.

Sometimes you don't know whether you are in insert mode or command mode. Whenever vi does not respond as you expect, press ESC once or twice to check which mode you are in. When you hear the beep, you are in command mode.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.93.137