Starting vi and dabbling with it

Before you go running off to use vi, understand that it has two modes (both of which look pretty much like Figure 4.10):

Figure 4.10. The vi editor innundates you with tons of onscreen help and advice, as shown here. Well, documentation is available, but the vi interface itself isn't really helpful at all!


  • An input mode (sometimes called insert mode), in which the keys you press actually show up in the file that you're editing. You use this mode to add or change text.

  • A command mode, in which every keystroke is interpreted as a command. You use this mode to do everything except enter text.

What's confusing about vi is that it starts you in command mode, meaning that if you just start typing, you'll see some blank spaces, characters, and bits of words that you type—essentially, a bunch of garbage that does not exactly represent what you're typing—and you'll hear a lot of beeping. So, as we'll show you in the following steps, you'll need to access the input mode as soon as you start vi.

To start vi:

1.
vi

At the shell prompt, type vi. The program starts up and you'll see something like Figure 4.10. The ~ symbols show blank lines below the end of the file.

2.
i

Type i to get into input mode. This itself is a command issued in command mode, so it won't show up on the screen.

3.
hairy spiders lurk

In input mode, type anything you want. Everything you type will show up on the screen until you return to command mode by pressing . You can use the arrow keys to navigate up and down in the file line by line and and to scroll up and down, respectively.

Tip

To get help in vi, type man vi. See Chapter 1 for more about man pages.


Tip

If you're not sure what mode you're in, press to go into command mode. If you're already in command mode, you'll hear a beep. If you're in input mode, you'll change to command mode.


Tip

You can open specific files or even multiple files when you access vi. At the shell prompt, type vi filetoedit (or whatever) to open a specific file. Or, for example, type vi *.html to open all of the HTML documents in a directory, then use :n (for next) to move to each subsequent file.


Tip

See Adding and deleting text with vi later in this chapter for more details about editing in vi.


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

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