- Choosing an Editor: nano/pico or vi/vim
- Starting nano and Dabbling with It
- Saving in nano
- Cutting and Pasting Text Blocks in nano
- Checking Spelling in nano
- Getting Help in nano
- Exiting nano
- Starting vi (or vim) and Dabbling with It
- Saving in vi
- Adding and Deleting Text in vi
- Importing Files into vi
- Searching and Replacing in vi
- Exiting vi
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 ):
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:
At the shell prompt, type vi. The program starts up, and you’ll see something like . The ~ symbols show blank lines below the end of the file.
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.
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 . 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 and to scroll one screen forward and backward, respectively.