2. Simple Editing
Contents:
This chapter introduces you to editing with vi , and it is set up to be read as a tutorial. In it you will learn how to move the cursor and how to make some simple edits. If you've never worked with vi , you should read the entire chapter. Later chapters show you how to expand your skills to perform faster and more powerful edits. One of the biggest advantages for an adept user of vi is that there are so many options to choose from. (One of the biggest disadvantages for a newcomer to vi is that there are so many different editor commands.) You can't learn vi by memorizing every single vi command. Start out by learning the basic commands introduced in this chapter. Note the patterns of use that the commands have in common. As you learn vi , be on the lookout for more tasks that you can delegate to the editor, and then find the command that accomplishes it. In later chapters you will learn more advanced features of vi , but before you can handle the advanced, you must master the simple. This chapter covers:
2.1 vi Commandsvi 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.
[i]
There are several ways to tell
vi
that you want to begin insert mode.
One of the most common is to press
For example, suppose you have opened a new file and want to insert
the word "introduction". If you type the keystrokes
introduction
When you open a new file,
vi
starts in command mode and
interprets the first
keystroke ( 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. |
|