Publishers of technology books, eBooks, and videos for creative people

Home > Articles

  • Print
  • + Share This
This chapter is from the book

Starting vi (or vim) 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 red_a.jpg):

081fig01.jpg

Click to view larger image

red_a.jpg 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!

  • Insert mode (sometimes called input 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.
  • Normal mode (sometimes called command mode), in which every keystroke is interpreted as a command. You use this mode to do everything except enter text.

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 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 insert 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 gray_a.jpg. The ~ symbols show blank lines below the end of the file.

  2. i

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

  3. hairy spiders lurk

    In insert mode, type anything you want.

    Everything you type will show up on the screen until you return to normal mode by pressing esc.jpg. When you are in normal mode, you can use the arrow keys to navigate up and down in the file line by line and use ctrl-f.jpg and ctrl-b.jpg to scroll one screen forward and backward, respectively.

  • + Share This
  • 🔖 Save To Your Account