We welcome comments and suggestions about this tutorial and the UNIX documentation in general.
Authors --September 1981NOTE:
UNIX is a trademark of Bell
Laboratories.
These lessons assume no prior familiarity with computers or with text editing. They consist of a series of text editing sessions which lead you through the fundamental steps of creating and revising text. After scanning each lesson and before beginning the next, you should practice the examples at a terminal to get a feeling for the actual process of text editing. If you set aside some time for experimentation, you will soon become familiar with using the computer to write and modify text. In addition to the actual use of the text editor, other features of UNIX will be very important to your work. You can begin to learn about these other features by reading ``Communicating with UNIX'' or one of the other tutorials that provide a general introduction to the system. You will be ready to proceed with this lesson as soon as you are familiar with (1) your terminal and its special keys, (2) the login procedure, (3) and the ways of correcting typing errors. Let's first define some terms:
:login:Type your login name, which identifies you to UNIX, on the same line as the login message, and press RETURN. If the terminal you are using has both upper and lower case, be sure you enter your login name in lower case; otherwise UNIX assumes your terminal has only upper case and will not recognize lower case letters you may type. UNIX types ``:login:'' and you reply with your login name, for example ``susan'':
:login: susan (and press the RETURN key)(In the examples, input you would type appears in bold face to distinguish it from the responses from UNIX.)
UNIX will next respond with a request for a password as an additional precaution to prevent unauthorized people from using your account. The password will not appear when you type it, to prevent others from seeing it. The message is:
Password: (type your password and press RETURN)If any of the information you gave during the login sequence was mistyped or incorrect, UNIX will respond with
Login incorrect. :login:in which case you should start the login process anew. Assuming that you have successfully logged in, UNIX will print the message of the day and eventually will present you with a % at the beginning of a fresh line. The % is the UNIX prompt symbol which tells you that UNIX is ready to accept a command.
% edit text (followed by a RETURN) "text" No such file or directory :If you typed the command correctly, you will now be in communication with edit. Edit has set aside a buffer for use as a temporary working space during your current editing session. It also checked to see if the file you named, ``text'', already existed. It was unable to find such a file, since ``text'' is a new file we are about to create. Edit confirms this with the line:
"text" No such file or directoryOn the next line appears edit's prompt ``:'', announcing that you are in command mode and edit expects a command from you. You may now begin to create the new file.
% editor editor: Command not found %Your mistake in calling edit ``editor'' was treated by UNIX as a request for a program named ``editor''. Since there is no program named ``editor'', UNIX reported that the program was ``not found''. A new % indicates that UNIX is ready for another command, and you may then enter the correct command.
:login: susan Password: ... A Message of General Interest ... % edit text "text" No such file or directory :
% edit text :append
:add add: Not an editor command :When you receive a diagnostic message, check what you typed in order to determine what part of your command confused edit. The message above means that edit was unable to recognize your mistyped command and, therefore, did not execute it. Instead, a new ``:'' appeared to let you know that edit is again ready to execute a command.
Leaving append mode does not destroy the text in the buffer. You have to leave append mode to do any of the other kinds of editing, such as changing, adding, or printing text. If you type a period as the first character and type any other character on the same line, edit will believe you want to remain in append mode and will not let you out. As this can be very frustrating, be sure to type only the period and the RETURN key.
This is a good place to learn an important lesson about computers and text: a blank space is a character as far as a computer is concerned. If you so much as type a period followed by a blank (that is, type a period and then the space bar on the keyboard), you will remain in append mode with the last line of text being:
.Let's say that the lines of text you enter are (try to type exactly what you see, including ``thiss''):
This is some sample text. And thiss is some more text. Text editing is strange, but nice. .The last line is the period followed by a RETURN that gets you out of append mode.
The usual erase character is the backspace (control-H), and you can correct typing errors in the line you are typing by holding down the CTRL key and typing the ``H'' key. If you try typing control-H you will notice that the terminal backspaces in the line you are on. You can backspace over your error, and then type what you want to be the rest of the line.
If you make a bad start in a line and would like to begin again, you can either backspace to the beginning of the line or you can use the at-sign ``@'' to erase everything on the line:
Text edtiing is strange, but@ Text editing is strange, but nice.When you type the at-sign (@), you erase the entire line typed so far and are given a fresh line to type on. You may immediately begin to retype the line. This, unfortunately, does not help after you type the line and press RETURN. To make corrections in lines that have been completed, it is necessary to use the editing commands covered in the next session and those that follow.
:writeEdit will copy the contents of the buffer to a disk file. If the file does not yet exist, a new file will be created automatically and the presence of a ``[New file]'' will be noted. The newly-created file will be given the name specified when you entered the editor, in this case ``text''. To confirm that the disk file has been successfully written, edit will repeat the filename and give the number of lines and the total number of characters in the file. The buffer remains unchanged by the ``write'' command. All of the lines that were written to disk will still be in the buffer, should you want to modify or add to them.
Edit must have a filename to use before it can write a file. If you forgot to indicate the name of the file when you began the editing session, edit will print
No current filenamein response to your write command. If this happens, you can specify the filename in a new write command:
:write textAfter the ``write'' (or ``w''), type a space and then the name of the file.
:write "text" [New file] 3 lines, 90 characters :quit %The % is from UNIX to tell you that your session with edit is over and you may command UNIX further. Since we want to end the entire session at the terminal, we also need to exit from UNIX. In response to the UNIX prompt of ``%'' type the command
%logoutThis will end your session with UNIX, and will ready the terminal for the next user. It is always important to type logout at the end of a session to make absolutely sure no one could accidentally stumble into your abandoned session and thus gain access to your files, tempting even the most honest of souls.
This is the end of the first session on UNIX text editing.
:login: susan (carriage return) Password: (give password and carriage return) ... A Message of General Interest ... %When you indicate you want to edit, you can specify the name of the file you worked on last time. This will start edit working, and it will fetch the contents of the file into the buffer, so that you can resume editing the same file. When edit has copied the file into the buffer, it will repeat its name and tell you the number of lines and characters it contains. Thus,
% edit text "text" 3 lines, 90 characters :means you asked edit to fetch the file named ``text'' for editing, causing it to copy the 90 characters of text into the buffer. Edit awaits your further instructions, and indicates this by its prompt character, the colon (:). In this session, we will append more text to our file, print the contents of the buffer, and learn to change the text of a line.
:a This is text added in Session 2. It doesn't mean much here, but it does illustrate the editor. .You may recall that once you enter append mode using the ``a'' (or ``append'') command, you need to type a line containing only a period (.) to exit append mode.
Interrupt :Any command that edit might be executing is terminated by rub or delete, causing edit to prompt you for a new command. If you are appending text at the time, you will exit from append mode and be expected to give another command. The line of text you were typing when the append command was interrupted will not be entered into the buffer.
:1,$pThe ``1''- stands for line 1 of the buffer ( The numeral ``one'' is the top left-most key, and should not be confused with the letter ``el''. ) , the ``$'' is a special symbol designating the last line of the buffer, and ``p'' (or print) is the command to print from line 1 to the end of the buffer. The command ``1,$p'' gives you:
This is some sample text. And thiss is some more text. Text editing is strange, but nice. This is text added in Session 2. It doesn't mean much here, but it does illustrate the editor.Occasionally, you may accidentally type a character that can't be printed, which can be done by striking a key while the CTRL key is pressed. In printing lines, edit uses a special notation to show the existence of non-printing characters. Suppose you had introduced the non-printing character ``control-A'' into the word ``illustrate'' by accidently pressing the CTRL key while typing ``a''. This can happen on many terminals because the CTRL key and the ``A'' key are beside each other. If your finger presses between the two keys, control-A results. When asked to print the contents of the buffer, edit would display
it does illustr^Ate the editor.To represent the control-A, edit shows ``^A''. The sequence ``^'' followed by a capital letter stands for the one character entered by holding down the CTRL key and typing the letter which appears after the ``^''. We'll soon discuss the commands that can be used to correct this typing error.
In looking over the text we see that ``this'' is typed as ``thiss'' in the second line, a deliberate error so we can learn to make corrections. Let's correct the spelling.
:/thiss/By typing /thiss/ and pressing RETURN, you instruct edit to search for ``thiss''. If you ask edit to look for a pattern of characters which it cannot find in the buffer, it will respond ``Pattern not found''. When edit finds the characters ``thiss'', it will print the line of text for your inspection:
And thiss is some more text.Edit is now positioned in the buffer at the line it just printed, ready to make a change in the line.
In particular, when you bring a file into the buffer, you will be located at the last line in the file, where the editor left off copying the lines from the file to the buffer. If your first editing command is ``append'', the lines you enter are added to the end of the file, after the current line - the last line in the file.
You can refer to your current location in the buffer by the symbol period (.) usually known by the name ``dot''. If you type ``.'' and carriage return you will be instructing edit to print the current line:
:. And thiss is some more text.If you want to know the number of the current line, you can type .= and press RETURN, and edit will respond with the line number:
:.= 2If you type the number of any line and press RETURN, edit will position you at that line and print its contents:
:2 And thiss is some more text.You should experiment with these commands to gain experience in using them to make changes.
:nu 2 And thiss is some more text.Note that the shortest abbreviation for the number command is ``nu'' (and not ``n'', which is used for a different command). You may specify a range of lines to be listed by the number command in the same way that lines are specified for print. For example, 1,$nu lists all lines in the buffer with their corresponding line numbers.
2s/thiss/this/We first indicate the line to be changed, line 2, and then type an ``s'' to indicate we want edit to make a substitution. Inside the first set of slashes are the characters that we want to change, followed by the characters to replace them, and then a closing slash mark. To summarize:
2s/ what is to be changed / what to change it to /If edit finds an exact match of the characters to be changed it will make the change only in the first occurrence of the characters. If it does not find the characters to be changed, it will respond:
Substitute pattern match failedindicating that your instructions could not be carried out. When edit does find the characters that you want to change, it will make the substitution and automatically print the changed line, so that you can check that the correct substitution was made. In the example,
:2s/thiss/this/ And this is some more text.line 2 (and line 2 only) will be searched for the characters ``thiss'', and when the first exact match is found, ``thiss'' will be changed to ``this''. Strictly speaking, it was not necessary above to specify the number of the line to be changed. In
:s/thiss/this/edit will assume that we mean to change the line where we are currently located (``.''). In this case, the command without a line number would have produced the same result because we were already located at the line we wished to change.
For another illustration of the substitute command, let us choose the line:
Text editing is strange, but nice.You can make this line a bit more positive by taking out the characters ``strange, but '' so the line reads:
Text editing is nice.A command that will first position edit at the desired line and then make the substitution is:
:/strange/s/strange, but //What we have done here is combine our search with our substitution. Such combinations are perfectly legal, and speed up editing quite a bit once you get used to them. That is, you do not necessarily have to use line numbers to identify a line to edit. Instead, you may identify the line you want to change by asking edit to search for a specified pattern of letters that occurs in that line. The parts of the above command are:
/strange/ tells edit to find the characters ``strange'' in the text s tells edit to make a substitution /strange, but // substitutes nothing at all for the characters ``strange, but ''You should note the space after ``but'' in ``/strange, but /''. If you do not indicate that the space is to be taken out, your line will read:
Text editing is nice.which looks a little funny because of the extra space between ``is'' and ``nice''. Again, we realize from this that a blank space is a real character to a computer, and in editing text we need to be aware of spaces within a line just as we would be aware of an ``a'' or a ``4''.
:1zedit will start with line 1 and continue printing lines, stopping either when the screen of your terminal is full or when the last line in the buffer has been printed. If you want to read the next segment of text, type the command
:zIf no starting line number is given for the z command, printing will start at the ``current'' line, in this case the last line printed. Viewing lines in the buffer one screen full at a time is known as paging. Paging can also be used to print a section of text on a hard-copy terminal.
:q No write since last change (:quit! overrides) :This is edit's warning that you have not written the modified contents of the buffer to disk. You run the risk of losing the work you did during the editing session since you typed the latest write command. Because in this lesson we have not written to disk at all, everything we have done would have been lost if edit had obeyed the q command. If you did not want to save the work done during this editing session, you would have to type ``q!'' or (``quit!'') to confirm that you indeed wanted to end the session immediately, leaving the file as it was after the most recent ``write'' command. However, since you want to save what you have edited, you need to type:
:w "text" 6 lines, 171 charactersand then follow with the commands to quit and logout:
:q % logoutand hang up the phone or turn off the terminal when UNIX asks for a name. Terminals connected to the port selector will stop after the logout command, and pressing keys on the keyboard will do nothing.
This is the end of the second session on UNIX text editing.
Did you remember to give the name of the file you wanted to edit? That is, did you type
% edit textor simply
% editBoth ways get you in contact with edit, but the first way will bring a copy of the file named ``text'' into the buffer. If you did forget to tell edit the name of your file, you can get it into the buffer by typing:
:e text "text" 6 lines, 171 charactersThe command edit, which may be abbreviated e, tells edit that you want to erase anything that might already be in the buffer and bring a copy of the file ``text'' into the buffer for editing. You may also use the edit (e) command to change files in the middle of an editing session, or to give edit the name of a new file that you want to create. Because the edit command clears the buffer, you will receive a warning if you try to edit a new file without having saved a copy of the old file. This gives you a chance to write the contents of the buffer to disk before editing the next file.
:2,4m$directs edit to move lines 2, 3, and 4 to the end of the buffer ($). The format for the move command is that you specify the first line to be moved, the last line to be moved, the move command ``m'', and the line after which the moved text is to be placed. So,
:1,3m6would instruct edit to move lines 1 through 3 (inclusive) to a location after line 6 in the buffer. To move only one line, say, line 4, to a location in the buffer after line 5, the command would be ``4m5''.
Let's move some text using the command:
:5,$m1 2 lines moved it does illustrate the editor.After executing a command that moves more than one line of the buffer, edit tells how many lines were affected by the move and prints the last moved line for your inspection. If you want to see more than just the last line, you can then use the print (p), z, or number (nu) command to view more text. The buffer should now contain:
This is some sample text. It doesn't mean much here, but it does illustrate the editor. And this is some more text. Text editing is nice. This is text added in Session 2.You can restore the original order by typing:
:4,$m1or, combining context searching and the move command:
:/And this is some/,/This is text/m/This is some sample/(Do not type both examples here!) The problem with combining context searching with the move command is that your chance of making a typing error in such a long command is greater than if you type line numbers.
:2,5copy $makes a copy of lines 2 through 5, placing the added lines after the buffer's end ($). Experiment with the copy command so that you can become familiar with how it works. Note that the shortest abbreviation for copy is co (and not the letter ``c'', which has another meaning).
This is text added in Session 2.from the buffer. If you know the number of the line to be deleted, you can type that number followed by delete or d. This example deletes line 4, which is ``This is text added in Session 2.'' if you typed the commands suggested so far.
:4d It doesn't mean much here, butHere ``4'' is the number of the line to be deleted, and ``delete'' or ``d'' is the command to delete the line. After executing the delete command, edit prints the line that has become the current line (``.''). If you do not happen to know the line number you can search for the line and then delete it using this sequence of commands:
:/added in Session 2./ This is text added in Session 2. :d It doesn't mean much here, butThe ``/added in Session 2./'' asks edit to locate and print the line containing the indicated text, starting its search at the current line and moving line by line until it finds the text. Once you are sure that you have correctly specified the line you want to delete, you can enter the delete (d) command. In this case it is not necessary to specify a line number before the ``d''. If no line number is given, edit deletes the current line (``.''), that is, the line found by our search. After the deletion, your buffer should contain:
This is some sample text. And this is some more text. Text editing is nice. It doesn't mean much here, but it does illustrate the editor. And this is some more text. Text editing is nice. This is text added in Session 2. It doesn't mean much here, butTo delete both lines 2 and 3:
And this is some more text. Text editing is nice.you type
:2,3d 2 lines deletedwhich specifies the range of lines from 2 to 3, and the operation on those lines - ``d'' for delete. If you delete more than one line you will receive a message telling you the number of lines deleted, as indicated in the example above.
The previous example assumes that you know the line numbers for the lines to be deleted. If you do not you might combine the search command with the delete command:
:/And this is some/,/Text editing is nice./d
A search based on too few characters may result in the wrong lines being deleted, which edit will do as easily as if you had meant it. For this reason, it is usually safer to specify the search and then delete in two separate steps, at least until you become familiar enough with using the editor that you understand how best to specify searches. For a beginner it is not a bad idea to double-check each command before pressing RETURN to send the command on its way.
It is possible to undo only commands which have the power to change the buffer - for example, delete, append, move, copy, substitute, and even undo itself. The commands write (w) and edit (e), which interact with disk files, cannot be undone, nor can commands that do not change the buffer, such as print. Most importantly, the only command that can be reversed by undo is the last ``undo-able'' command you typed. You can use control-H and @ to change commands while you are typing them, and undo to reverse the effect of the commands after you have typed them and pressed RETURN.
To illustrate, let's issue an undo command. Recall that the last buffer-changing command we gave deleted the lines formerly numbered 2 and 3. Typing undo at this moment will reverse the effects of the deletion, causing those two lines to be replaced in the buffer.
:u 2 more lines in file after undo And this is some more text.Here again, edit informs you if the command affects more than one line, and prints the text of the line which is now ``dot'' (the current line).
:.=If we type ``.='' we are asking for the number of the line, and if we type ``.'' we are asking for the text of the line.
In this editing session and the last, we used the dollar sign to indicate the end of the buffer in commands such as print, copy, and move. The dollar sign as a command asks edit to print the last line in the buffer. If the dollar sign is combined with the equal sign ($=) edit will print the line number corresponding to the last line in the buffer.
``.'' and ``$'', then, represent line numbers. Whenever appropriate, these symbols can be used in place of line numbers in commands. For example
:.,$dinstructs edit to delete all lines from the current line (.) to the end of the buffer.
-3pThis tells edit to move back to a position 3 lines before the current line (.) and print that line. You can move forward in the buffer similarly:
+2pinstructs edit to print the line that is 2 ahead of your current position.
You may use ``+'' and ``-'' in any command where edit accepts line numbers. Line numbers specified with ``+'' or ``-'' can be combined to print a range of lines. The command
:-1,+2copy$makes a copy of 4 lines: the current line, the line before it, and the two after it. The copied lines will be placed after the last line in the buffer ($), and the original lines referred to by ``-1'' and ``+2'' remain where they are.
Try typing only ``-''; you will move back one line just as if you had typed ``-1p''. Typing the command ``+'' works similarly. You might also try typing a few plus or minus signs in a row (such as ``+++'') to see edit's response. Typing RETURN alone on a line is the equivalent of typing ``+1p''; it will move you one line ahead in the buffer and print that line.
If you are at the last line of the buffer and try to move further ahead, perhaps by typing a ``+'' or a carriage return alone on the line, edit will remind you that you are at the end of the buffer:
At end-of-fileor
Not that many lines in bufferSimilarly, if you try to move to a position before the first line, edit will print one of these messages:
Nonzero address required on this commandor
Negative address - first buffer line is 1The number associated with a buffer line is the line's ``address'', in that it can be used to locate the line.
This is some sample text. And this is some more text.to read
This text was created with the UNIX text editor.To do so, you type:
:1,2c 2 lines changed This text was created with the UNIX text editor. . :In the command 1,2c we specify that we want to change the range of lines beginning with 1 and ending with 2 by giving line numbers as with the print command. These lines will be deleted. After you type RETURN to end the change command, edit notifies you if more than one line will be changed and places you in text input mode. Any text typed on the following lines will be inserted into the position where lines were deleted by the change command. You will remain in text input mode until you exit in the usual way, by typing a period alone on a line. Note that the number of lines added to the buffer need not be the same as the number of lines deleted.
This is the end of the third session on text editing with UNIX.
To print all lines containing a certain sequence of characters (say, ``text'') the command is:
:g/text/pThe ``g'' instructs edit to make a global search for all lines in the buffer containing the characters ``text''. The ``p'' prints the lines found.
To issue a global command, start by typing a ``g'' and then a search pattern identifying the lines to be affected. Then, on the same line, type the command to be executed for the identified lines. Global substitutions are frequently useful. For example, to change all instances of the word ``text'' to the word ``material'' the command would be a combination of the global search and the substitute command:
:g/text/s/text/material/gNote the ``g'' at the end of the global command, which instructs edit to change each and every instance of ``text'' to ``material''. If you do not type the ``g'' at the end of the command only the first instance of ``text'' in each line will be changed (the normal result of the substitute command). The ``g'' at the end of the command is independent of the ``g'' at the beginning. You may give a command such as:
:5s/text/material/gto change every instance of ``text'' in line 5 alone. Further, neither command will change ``text'' to ``material'' if ``Text'' begins with a capital rather than a lower-case t.
Edit does not automatically print the lines modified by a global command. If you want the lines to be printed, type a ``p'' at the end of the global command:
:g/text/s/text/material/gpYou should be careful about using the global command in combination with any other - in essence, be sure of what you are telling edit to do to the entire buffer. For example,
:g/ /d 72 less lines in file after globalwill delete every line containing a blank anywhere in it. This could adversely affect your document, since most lines have spaces between words and thus would be deleted. After executing the global command, edit will print a warning if the command added or deleted more than one line. Fortunately, the undo command can reverse the effects of a global command. You should experiment with the global command on a small file of text to see what it can do for you.
:/text/s/text/texts/as we have done in the past, or a somewhat abbreviated command:
:/text/s//texts/In this example, the characters to be changed are not specified - there are no characters, not even a space, between the two slash marks that indicate what is to be changed. This lack of characters between the slashes is taken by the editor to mean ``use the characters we last searched for as the characters to be changed.''
Similarly, the last context search may be repeated by typing a pair of slashes with nothing between them:
:/does/ It doesn't mean much here, but :// it does illustrate the editor.(You should note that the search command found the characters ``does'' in the word ``doesn't'' in the first search request.) Because no characters are specified for the second search, the editor scans the buffer for the next occurrence of the characters ``does''.
Edit normally searches forward through the buffer, wrapping around from the end of the buffer to the beginning, until the specified character string is found. If you want to search in the reverse direction, use question marks (?) instead of slashes to surround the characters you are searching for.
It is also possible to repeat the last substitution without having to retype the entire command. An ampersand (& used as a command repeats the most recent substitute command, using the same search and replacement patterns. After altering the current line by typing
:s/text/texts/you type
:/text/&or simply
://&to make the same change on the next line in the buffer containing the characters ``text''.
:g/text.$/s//material./ptells the editor to search for all lines ending in ``text.'' (and nothing else, not even a blank space), to change each final ``text.'' to ``material.'', and print the changed lines.
The symbol ``^'' indicates the beginning of a line. Thus,
:s/^/1. /instructs the editor to insert ``1.'' and a space at the beginning of the current line.
The characters ``$'' and ``^'' have special meanings only in the context of searching. At other times, they are ordinary characters. If you ever need to search for a character that has a special meaning, you must indicate that the character is to lose temporarily its special significance by typing another special character, the backslash (\), before it.
:s/\$/dollar/looks for the character ``$'' in the current line and replaces it by the word ``dollar''. Were it not for the backslash, the ``$'' would have represented ``the end of the line'' in your search rather than the character ``$''. The backslash retains its special significance unless it is preceded by another backslash.
:!rm junk ! :The exclamation mark (!) indicates that the rest of the line is to be processed as a shell command. If the buffer contents have not been written since the last change, a warning will be printed before the command is executed:
[No write since last change]The editor prints a ``!'' when the command is completed. The tutorial ``Communicating with UNIX'' describes useful features of the system, of which the editor is only one part.
:w chapter3 "chapter3" [new file] 283 lines, 8698 charactersThe current filename remembered by the editor will not be changed as a result of the write command. Thus, if the next write command does not specify a name, edit will write onto the current file (``draft3'') and not onto the file ``chapter3''.
:f "text" [Modified] line 3 of 4 --75%--If the contents of the buffer have changed since the last time the file was written, the editor will tell you that the file has been ``[Modified]''. After you save the changes by writing onto a disk file, the buffer will no longer be considered modified:
:w "text" 4 lines, 88 characters :f "text" line 3 of 4 --75%--
:$r example "example" 18 lines, 473 charactersreads the file ``example'' and adds it to the buffer after the last line. The current filename is not changed by the read command.
:45,$w endingHere all lines from 45 through the end of the buffer are written onto the file named ending. The lines remain in the buffer as part of the document you are editing, and you may continue to edit the entire buffer. Your original file is unaffected by your command to write part of the buffer to another file. Edit still remembers whether you have saved changes to the buffer in your original file or not.
:recover chap6Recover is sometimes unable to save the entire buffer successfully, so always check the contents of the saved buffer carefully before writing it back onto the original file. For best results, write the buffer to a new file temporarily so you can examine it without risk to the original file. Unfortunately, you cannot use the recover command to retrieve a file you removed using the shell command rm.
:preserveand wait for the reply,
File preserved.If you do not receive this reply, seek help immediately. Do not simply leave the editor. If you do, the buffer will be lost, and you may not be able to save your file. If the reply is ``File preserved.'' you can leave the editor (or logout) to remedy the situation. After a preserve, you can use the recover command once the problem has been corrected, or the -r option of the edit command if you leave the editor and want to return.
If you make an undesirable change to the buffer and type a write command before discovering your mistake, the modified version will replace any previous version of the file. Should you ever lose a good version of a document in this way, do not panic and leave the editor. As long as you stay in the editor, the contents of the buffer remain accessible. Depending on the nature of the problem, it may be possible to restore the buffer to a more complete state with the undo command. After fixing the damaged buffer, you can again write the file to disk.
Edit commands work the same way in ex, but the editing environment is somewhat different. You should be aware of a few differences that exist between the two versions of the editor. In edit, only the characters ``^'', ``$'', and ``\'' have special meanings in searching the buffer or indicating characters to be changed by a substitute command. Several additional characters have special meanings in ex, as described in the Ex Reference Manual. Another feature of the edit environment prevents users from accidently entering two alternative modes of editing, open and visual, in which the editor behaves quite differently from normal command mode. If you are using ex and the editor behaves strangely, you may have accidently entered open mode by typing ``o''. Type the ESC key and then a ``Q'' to get out of open or visual mode and back into the regular editor command mode. The document An Introduction to Display Editing with Vi provides a full discussion of visual mode.
addressing, see line numbers ampersand, 20 append mode, 6-7 append (a) command, 6, 7, 9 ``At end of file'' (message), 18 backslash (\), 21 buffer, 3 caret (^), 10, 20 change (c) command, 18 command mode, 5-6 ``Command not found'' (message), 6 context search, 10-12, 19-21 control characters (``^'' notation), 10 control-H, 7 copy (co) command, 15 corrections, 7, 16 current filename, 21 current line (.), 11, 17 delete (d) command, 15-16 dial-up, 5 disk, 3 documentation, 3, 23 dollar ($), 10, 11, 17, 20-21 dot (.) 11, 17 edit (text editor), 3, 5, 23 edit (e) command, 5, 9, 14 editing commands: append (a), 6, 7, 9 change (c), 18 copy (co), 15 delete (d), 15-16 edit (text editor), 3, 5, 23 edit (e), 5, 9, 14 file (f), 21-22 global (g), 19 move (m), 14-15 number (nu), 11 preserve (pre), 22-23 print (p), 10 quit (q), 8, 13 read (r), 22 recover (rec), 22, 23 substitute (s), 11-12, 19, 20 undo (u), 16-17, 23 write (w), 8, 13, 21, 22 z, 12-13 ! (shell escape), 21 $=, 17 +, 17 -, 17 //, 12, 20 ??, 20 ., 11, 17 .=, 11, 17 entering text, 3, 6-7 erasing characters (^H), 7 lines (@), 7 error corrections, 7, 16 ex (text editor), 23 Ex Reference Manual, 23 exclamation (!), 21 file, 3 file (f) command, 21-22 file recovery, 22-23 filename, 3, 21 global (g) command, 19 input mode, 6-7 Interrupt (message), 9 line numbers, see also current line dollar sign ($), 10, 11, 17 dot (.), 11, 17 relative (+ and -), 17 list, 10 logging in, 4-6 logging out, 8 ``Login incorrect'' (message), 5 minus (-), 17 move (m) command, 14-15 ``Negative address-first buffer line is 1'' (message), 18 ``No current filename'' (message), 8 ``No such file or directory'' (message), 5, 6 ``No write since last change'' (message), 21 non-printing characters, 10 ``Nonzero address required'' (message), 18 ``Not an editor command'' (message), 6 ``Not that many lines in buffer'' (message), 18 number (nu) command, 11 password, 5 period (.), 11, 17 plus (+), 17 preserve (pre) command, 22-23 print (p) command, 10 program, 3 prompts % (UNIX), 5 : (edit), 5, 6, 7 (append), 7 question (?), 20 quit (q) command, 8, 13 read (r) command, 22 recover (rec) command, 22, 23 recovery, see file recovery references, 3, 23 remove (rm) command, 21, 22 reverse command effects (undo), 16-17, 23 searching, 10-12, 19-21 shell, 21 shell escape (!), 21 slash (/), 11-12, 20 special characters (^, $, \), 10, 11, 17, 20-21 substitute (s) command, 11-12, 19, 20 terminals, 4-5 text input mode, 7 undo (u) command, 16-17, 23 UNIX, 3 write (w) command, 8, 13, 21, 22 z command, 12-13
this page is maintained by John Urban.
[Created: 19960901][Last modified: 19960901]