Lamb Linda - Learning the vi and Vim Editors стр 10.

Шрифт
Фон

commands, you lose all edits made in the buffer since the last time you saved the file.

vi normally wont let you throw away your edits. The exclamation point added to

the :e or :q command causes vi to override this prohibition, performing the operation

even though the buffer has been modified.

Problems Saving Files

You try to write your file, but you get one of the following messages:

File exists

File file exists - use w!

[Existing file]

File is read only

Type :w! file to overwrite the existing file, or type :w newfile to save the edited

version in a new file.

You want to write a file, but you dont have write permission for it. You get the message

Permission denied.

Use :w newfile to 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 dont have write permission for the directory, type :w pathname/file to

write out the buffer to a directory in which you do have write permission (such as

your home directory, or /tmp).

10 | Chapter 1:The vi Text Editor

You try to write your file, but you get a message telling you that the file system is full.

Type :!rm junkfile to delete a (large) unneeded file and free some space. (Starting

an ex command with an exclamation point gives you access to Unix.)

Or type :!df to see whether theres any space on another file system. If there is,

choose a directory on that file system and write your file to it with :w pathname .

(df is the Unix command to check a disks free space.)

The system puts you into open mode and tells you that the file system is full.

The disk with vis temporary files is filled up. Type :!ls /tmp to see whether there

are any files you can remove to gain some disk space.# If there are, create a tem-

porary 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 exit to terminate the shell

and return to vi. (On modern Unix systems, when using a job-control shell, you

can simply type CTRL-Z to suspend vi and return to the Unix prompt; type fg to

return to vi.) Once youve freed up some space, write your file with :w!.

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 :pre (short

for :preserve). If that doesnt 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 youre done. Then write your file

with :w!.

Exercises

The only way to learn vi is to practice. You now know enough to create a new file and

to return to the Unix prompt. Create a file called practice, insert some text, and then

save and quit the file.

Open a file called practice in the current directory:

vi practice

Insert text:

i any text you like

Return to command mode:

ESC

Quit vi, saving edits:

ZZ

# Your vi may keep its temporary files in /usr/tmp, /var/tmp, or your current directory; you may need to poke

around a bit to figure out where exactly youve run out of room. Vim generally keeps its temporary file in the

same directory as the file being edited.

Quitting Without Saving Edits | 11

CHAPTER 2

Simple Editing

This chapter introduces you to editing with vi, and it is set up to be read as a tutorial.

In it you will learn how to move the cursor and how to make some simple edits. If

youve never worked with vi, you should read the entire chapter.

Later chapters will show you how to expand your skills to perform faster and more

powerful edits. One of the biggest advantages for an adept user of vi is that there are

so many options to choose from. (One of the biggest disadvantages for a newcomer to

vi is that there are so many different editor commands.)

You cant learn vi by memorizing every single vi command. Start out by learning the

basic commands introduced in this chapter. Note the patterns of use that the com-

mands have in common.

As you learn vi, be on the lookout for more tasks that you can delegate to the editor,

and then find the command that accomplishes it. In later chapters you will learn more

advanced features of vi, but before you can handle the advanced, you must master the

simple.

This chapter covers:

Moving the cursor

Adding and changing text

Deleting, moving,

and copying text

More ways to enter insert mode

vi Commands

vi has two modes: command mode and insert mode. As soon as you enter a file, you

are in command mode, and the editor is waiting for you to enter a command. Com-

mands enable you to move anywhere in the file, to perform edits, or to enter insert

mode to add new text. Commands can also be given to exit the file (saving or ignoring

your edits) in order to return to the Unix prompt.

13

You can think of the different modes as representing two different keyboards. In insert

mode, your keyboard functions like a typewriter. In command mode, each key has a

Ваша оценка очень важна

0
Шрифт
Фон

Помогите Вашим друзьям узнать о библиотеке