Starting vi and Dabbling with It


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.11):

  • 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.

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

    Figure 4.11. The vi editor inundates 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!

What's confusing for many people about vi is that it starts you in command mode, meaning that if you just start typing, you may see some blank spaces, characters, and bits of words that you typeessentially, a bunch of garbage that does not exactly represent what you're typingand 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.11. 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 . When you are in command mode, you can use the arrow keys to navigate up and down in the file line by line and and to scroll one screen forward and backward, respectively.

Tips

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

  • 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.

  • Many Unix-like systems, including Linux and Mac OS, actually provide a program called vim in the place of vi. vim (VI iMproved) is like vi but feature-rich and more flexible, and you still start it with the command vi.

  • 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.

  • See Adding and Deleting Text in vi later in this chapter for more details about editing in vi.





Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net