Problem Checklists: Appendix B - Learning the vi and Vim Editors, Seventh Editionby Linda Lamb, Arnold Robbins, Elbert Hannah
This excerpt is from Learning the vi and Vim Editors, Seventh Edition.
The standard guide for vi since 1986, this book has been expanded to include detailed information on vim, the leading vi clone that includes extra features for both beginners and power users. You learn text editing basics and advanced tools for both editors, such as writing macros and scripts to extend the editor, power tools for programmers, multi-window editing -- all in the easy-to-follow style that has made this book a classic.
This appendix consolidates the problem checklists that are provided throughout Part I, “Basic and Advanced vi”. Here they are presented in one place for ease of reference.
When you invoke vi , the message
Your terminal type is probably incorrectly identified. Quit the editing session immediately by typing
:q. Check the environment variable
$TERM. It should be set to the name of your terminal. Alternatively, ask your system administrator to provide an adequate terminal type setting.
You see one of the following messages:
Visual needs addressable cursor or upline capability Bad termcap entry Termcap entry too long
terminal: Unknown terminal type Block device required Not a typewriter
Either your terminal type is undefined, or there’s probably something wrong with your
:qto quit. Check your
$TERMenvironment variable, or ask your system administrator to select a terminal type for your environment.
[new file]message appears when you think a file already exists.
Check that you have used the correct case in the filename (filenames are often case-sensitive). If you have, you are probably in the wrong directory. Enter
:qto quit. Then check to see that you are in the correct directory for that file (enter pwd at the Unix prompt). If you are in the right directory, check the list of files in the directory (with ls) to see whether the file exists under a slightly different name.
You invoke vi , but you get a colon prompt (indicating that you’re in ex line-editing mode).
You probably typed an interrupt before vi could draw the screen. Enter vi by typing
viat the ex prompt (
One of the following messages appears:
[Read only] File is read only Permission denied
“Read only” means that you can only look at the file; you cannot save any changes you make. You may have invoked vi in view mode (with view or
vi -R), or you do not have write permission for the file. See the next section, the section called “Problems Saving Files”.
One of the following messages appears:
Bad file number Block special file Character special file Directory Executable Non-ascii file
The file you’ve called up to edit is not a regular text file. Type
:q!to quit, then check the file you wish to edit, perhaps with the file command.
When you type
:qbecause of one of the previously mentioned difficulties, this message appears:
No write since last change (:quit! overrides).
You have modified the file without realizing it. Type
:q!to leave vi. Your changes from this session will not be saved in the file.
You try to write your file, but you get one of the following messages:
File exists File
fileexists - use w! [Existing file] File is read only
You want to write a file, but you don’t have write permission for it. You get the message “Permission denied.”
newfileto write out the buffer into a new file. If you have write permission for the directory, you can use mv to replace the original version with your copy of it. If you don’t have write permission for the directory, type
pathname/fileto write out the buffer to a directory in which you do have write permission (such as your home directory, or
You try to write your file, but you get a message telling you that the file system is full.
:!dfto see whether there’s any space on another file system. If there is, choose a directory on that file system and write your file to it with
pathname. (df is the Unix command to check a
The system puts you into open mode and tells you that the file system is full.
The disk with vi’s temporary files is filled up. Type
:!ls /tmpto see whether there are any files you can remove to gain some disk space. If there are, create a temporary Unix shell from which you can remove files or issue other Unix commands. You can create a shell by typing
:sh; type CTRL-D or
exitto terminate the shell and return to vi. (On most Unix systems, when using a job-control shell, you can simply type CTRL-Z to suspend vi and return to the Unix prompt; type
fgto return to vi.) Once you’ve freed up some space, write your file with
You try to write your file, but you get a message telling you that your disk quota has been reached.
Try to force the system to save your buffer with the ex command
:preserve). If that doesn’t work, look for some files to remove. Use
:sh(or CTRL-Z if you are using a job-control system) to move out of vi and remove files. Use CTRL-D (or
fg) to return to vi when you’re done. Then write your file with
When you type commands, text jumps around on the screen and nothing works the way it’s supposed to.
Make sure you’re not typing the
Jcommand when you mean
You may have hit the CAPS LOCK key without noticing it. vi is case-sensitive; that is, uppercase commands (
J, etc.) are different from lowercase commands (
j), so all your commands are being interpreted not as lowercase but as uppercase commands. Press the CAPS LOCK key again to return to lowercase, press ESC to ensure that you are in command mode, then type either
Uto restore the last line changed or
uto undo the last command. You’ll probably also have to do some additional editing to fully restore the garbled part of your file.
You’ve deleted the wrong text and you want to get it back.
There are several ways to recover deleted text. If you’ve just deleted something and you realize you want it back, simply type
uto undo the last command (for example, a
dd). This works only if you haven’t given any further commands, since
uundoes only the most recent command. On the other hand, a
Uwill restore the line to its pristine state, the way it was before any changes were applied to it.
You can still recover a recent deletion, however, by using the
pcommand, since vi saves the last nine deletions in nine numbered deletion buffers. If you know, for example, that the third deletion back is the one you want to restore, type:
to “put” the contents of buffer number 3 on the line below the cursor. This works only for a deleted line. Words, or a portion of a line, are not saved in a buffer. If you want to restore a deleted word or line fragment, and
uwon’t work, use the
pcommand by itself. This restores whatever you’ve last deleted.
 Your vi may keep its
temporary files in
/var/tmp, or your current
directory; you may need to poke around a bit to figure out where
exactly you’ve run out of room.
If you enjoyed this excerpt, buy a copy of Learning the vi and Vim Editors, Seventh Edition.