• Keine Ergebnisse gefunden

Quitting the Visual Editor

Im Dokument XE 500 (Seite 81-87)

If you wish to leave the editor instead of just writing, enter

:wq

This writes the contents of the editor buffer (including changes) back into the file you are editing and then quits the editor. You can also use the ZZ command to write and leave the editor. If you want to end an editing session and discard all changes, the following can be entered:

: q I

Be very careful not to use this command when you really want to save the changes made.

Example One

I Accessing, writing, and quitting a file.

1 Make a copy of a familiar file.

2 To access the file copy, enter the vi command and filename followed by pressing the RETURN key.

$ vi filename

2 The file name will appear in quotes at the bottom of the screen. The number of lines and the number of characters will appear momentarily next to the file name. The first part of the file will then appear on the screen. The cursor will be at the top left character in the file. The file name, number of lines, and number of characters will remain displayed on the bottom line of the screen.

3 Enter the colon command symbol.

The colon appears below the bottom line of the displayed file displacing the file name and the number of lines and characters.

4 Enter the write command.

:w

The w appears at the bottom of the screen next to the colon.

5 Press the RETURN key.

The file name in quotes, the number of lines, and the number of characters appear at the bottom of the screen.

6 Enter the quit command.

:q

A q will appear next to the colon at the bottom of the screen. After pressing the RETURN, the system prompt is displayed on the next line at the bottom of the screen. You have exited the vi editor. No change has occurred in your file. (The above procedure can be accomplished by entering :wq).

II Accessing and quitting a file after writing has occurred.

1 Access your file for the second time.

$ v I f I I ensme

Wait for a screen display. You could enter information at this time. In this exercise, no information will be entered.

2 Enter the write command.

:w

The write command appears at the bottom of the screen. After pressing the RETURN key, the file name in quotes, the number of lines, and the number of characters appear at the bottom of the screen.

3 Enter the quit command.

: q

The file name, number of lines, and number of characters is replaced by the :. A q appears at the bottom of the screen next to the colon. After pressing the RETURN key, the system prompt appears at the bottom of the screen. You have left the vi editor once again. If changes had been made in your buffer file, they would have been written into your original file.

III Accessing and quitting a file after writing has occurred--a second method.

Access your file.

$ vi filename

Wait for a screen display. You could enter information at this time. In this example no information will be entered.

2 Enter a write and quit.

:wq

A wq appears at the bottom of the screen next to the colon. After pressing the RETURN key, the file name, number of lines, and number of characters appear at the bottom of the screen. The system prompt appears on the next line. You have left the vi editor. If changes had been made in your buffer file, they would have been written into your original file.

IV Accessing and quitting a file after writing has occurred--a third method.

Access your file.

$ vi filename

Wait for a screen display. You could enter information at this time. In this example no information will be entered.

2 Enter the write and quit command in uppercase as follows:

zz

The system prompt appears at the bottom of the screen. You have left vi editor again. If changes had been made in your buffer file, they would have been written into your original file.

The ZZ command is identical to the :wq command, except that it does not respond with the file name, number of lines, and number of characters when no changes have been made.

V Accessing and quitting a file without saving changes.

Access your file.

$ v i ' ; lename

Wait for a screen display. You could enter information at this time. In this exercise, no information will be entered.

2 Enter the quit command without saving changes command.

: q I

The three characters appear at the bottom of the screen. After pressing the RETURN key, the system prompt appears at the bottom of the screen. If any changes had been made in your buffer file, they would not be saved.

VI Changing a file name.

1 Access your file.

$ v I f I I ename

Wait for a screen display. You could enter information at this time. In this example no information will be entered.

2 Enter:w followed by a space, your new file name, and a RETURN.

: w new' I I ename

At the bottom of the screen, the new file name appears in quotes. Next appears the note [New file], followed by the number of lines and the number of characters.

3 Enter the colon command symbol and the quit command.

:q

The system prompt appears at the bottom of the screen. In your directory, the original file exists without change. The new file now appears in your directory;

and if any changes had been made, they would be in the new file.

VII Starting a new file without input information.

Enter another new file.

$ vi newfllename2

At the bottom of the screen, the new file name appears in quotes followed by the note [New file]. A line of tildes (-) appears on the left side of the screen.

The cursor appears on a line above the tildes. You could enter information at this time.

2 Enter the write command.

:w

The new file name appears in quotes at the bottom of the screen followed by the message "[New file] 1 line,

1 character."

3 Quit the editor.

:q

The system prompt appears at the bottom of the screen. You now have a new empty file.

VIII Starting a new file with input information.

Enter another new file.

$ vi newfilename3 Wait for a screen display.

2 Write into the new file by typing a

then

Qwerty

and press the GO key.

The first letter H a" puts vi in the append mode and will not appear on the screen. "qwerty" is the appended information. The GO key is used to end the append mode. You have now entered information into a file.

3 Enter the following write and quit command:

zz

The new file name in quotes followed by [New file) 1 line, and 7 characters appears at the bottom of the screen. The system prompt appears on the next line.

You now have a new file in your directory containing

"qwerty."

Summary

:q :q!

:w :w Rswfils :wq ZZ

Quit vi editor when no changes have occurred since last write.

Quit vi editor and do not save changes since last write.

Write buffer to current file.

Write buffer to newfile.

Write and quit.

Write and quit.

Im Dokument XE 500 (Seite 81-87)