BSD 2 development
[unix-history] / doc / ex / edit.tut
CommitLineData
47d38f87
BJ
1.ND Draft:\ \ \ April 5, 1979
2.RP
3.TL
4Edit: A Tutorial
5.AU
6Ricki Blau
7.AU
8James Joyce
9.AI
10Computing Services
11University of California
12Berkeley, California 94720
13.AB
14.PP
15This narrative introduction to the use of the text editor
16.I edit
17assumes no prior familiarity with computers or with text editing.
18Its aim is to lead the beginning \s-2UNIX\(dg\s+2 user through the
19.FS
20\(dgUNIX is a trademark of Bell Laboratories.
21.FE
22fundamental steps of writing and revising a file of text.
23Edit,
24a version of the text editor
25.I ex,
26was designed to provide an informative environment
27for new and casual users.
28.PP
29This edition documents Version 2.0 of
30.I edit
31and
32.I ex .
33.PP
34We welcome comments and suggestions about this tutorial
35and the \s-2UNIX\s+2 documentation in general.
36Contact the \s-2UNIX\s+2 consultant in 217 Evans, 642-4072.
37.AE
38.SH
39.PP
40Text editing using a terminal connected to a computer
41allows a user to create, modify, and print text
42easily. Creating text is as easy as typing it much
43as one would on an electric typewriter.
44Modifying text involves telling the text editor
45what to add, change, or delete.
46Text is printed by giving the proper
47command to print the file contents, with or
48without special instructions as to the format
49of the desired output.
50.PP
51These lessons assume no prior familiarity with computers
52or with text editing.
53They consist of a series of text editing sessions
54which will lead you through the fundamental steps
55of creating and revising a file of text.
56After scanning each lesson and before beginning the next,
57you should follow the examples at a terminal to get a feeling
58for the actual process of text editing.
59Set aside some time for experimentation,
60and you will soon become familiar with using the
61computer to write and modify text.
62In addition to the actual use of the text editor,
63other features of \s-2UNIX\s0 will be very important to your work.
64You can begin to
65learn about these other features by
66reading ``Communicating with \s-2UNIX\s0''
67or one of the other tutorials
68which provide a general introduction to the system.
69You will be ready to proceed with this lesson as soon as
70you are familiar with your terminal and its special keys,
71the login procedure, and the ways of correcting typing errors.
72Let's first define some terms:
73.sp .5
74.IP program 12
75A set of instructions given to the computer,
76describing the sequence of steps which the computer performs
77in order to accomplish a specific task.
78As an example, a series of steps to balance your
79checkbook is a program.
80.IP UNIX
81\s-2UNIX\s0 is a special type of program,
82called an operating system, that supervises the machinery
83and all other programs comprising the total
84computer system.
85.IP edit
86.I edit
87is the name of the \s-2UNIX\s0 text editor which you will be learning to use,
88a program that aids you in writing or revising text.
89Edit was designed for beginning users,
90and is a simplified version of an editor called
91.I ex.
92.IP file
93Each \s-2UNIX\s0 account is allotted
94space for the permanent storage of information, such as programs, data or text.
95A file is a logical unit of data,
96for example, an essay, a program, or a chapter from a book,
97which is stored on a computer system.
98Once you create a file,
99it is kept until you instruct the system to remove it.
100You may create a file during one \s-2UNIX\s0 session, log out,
101and return to use it at a later time.
102Files contain anything you choose to write and store in them.
103The sizes of files vary to suit your needs;
104one file might hold only a single number while another might contain
105a very long document or program.
106The only way to save
107information from one session to the next is to store it in a file.
108.IP filename
109Filenames are used to distinguish one file from another,
110serving the same purpose as the labels of manila
111folders in a file cabinet.
112In order to write or access information in a file,
113you use the name of that file in a \s-2UNIX\s0 command,
114and the system will automatically locate the file.
115.IP disk
116Files are stored on an input/output device called a disk,
117which looks something like a stack of phonograph records.
118Each surface is coated with a material similar to the
119coating on magnetic recording tape, on which information is recorded.
120.IP buffer
121A temporary work space, made available to the user
122for the duration of a session of text editing
123and used for building and modifying
124the text file.
125We can imagine the buffer as a blackboard that is
126erased after each class, where each session with the editor
127is a class.
128.sp 2
129.SH
130.ce 1
131Session 1: Creating a File of Text
132.sp 1
133.PP
134To use the editor you must first make contact with the computer
135by logging in to \s-2UNIX\s0.
136We'll quickly review the standard \s-2UNIX\s0 login procedure.
137.PP
138If the terminal you are using is directly linked to the computer,
139turn it on and press carriage return,
140usually
141labelled ``\s-1RETURN\s+1''.
142If your terminal connects with the computer over a telephone line,
143turn on the terminal, dial the system access number,
144and, when you hear a high-pitched tone, place the receiver of
145the telephone in the acoustic coupler.
146Press carriage return once and await the login message:
147.DS I 1i
148:login:
149.DE
150.PP
151Type your login name, which identifies you to \s-2UNIX\s0,
152on the same line as the login
153message, and press carriage return.
154If the terminal you are using has both upper
155and lower case, be sure you enter your login name
156in lower case; otherwise \s-2UNIX\s0 assumes your terminal
157has only upper case and will not recognize lower case
158letters you may type.
159\s-2UNIX\s0 types ``:login:'' and you reply
160with your login name, for example ``susan'':
161.DS I 1i
162:login: \fBsusan\fR \fI(and press carriage return)\fR
163.DE
164(In the examples, input typed by the user appears in
165.B "bold face"
166to distinguish it from the responses from \s-2UNIX\s0.)
167.PP
168\s-2UNIX\s0 will next respond with a request for a password
169as an additional precaution to prevent
170unauthorized people from using your account.
171The password will not appear when you type it,
172to prevent others from seeing it.
173The message is:
174.DS I 1i
175Password: \fI(type your password and press carriage return)\fR
176.DE
177If any of the information you gave during the login
178sequence was mistyped or incorrect,
179\s-2UNIX\s0 will respond with
180.DS I 1i
181Login incorrect.
182.if t .sp .2v
183.if n .sp 1
184:login:
185.DE
186in which case you should start the login process anew.
187Assuming that you have successfully
188logged in, \s-2UNIX\s0
189will print the message of the day and eventually will present
190you with a % at the beginning of a fresh line.
191The % is the \s-2UNIX\s0 prompt symbol
192which tells you that \s-2UNIX\s0 is ready to accept a command.
193.bd I 3
194.SH
195Asking for \fIedit\fP
196.fl
197.bd I
198.PP
199You are ready to tell \s-2UNIX\s0 that you
200want to work with edit, the text editor.
201Now is a convenient time to choose
202a name for the file of text which you are about to create.
203To begin your editing session type
204.B edit
205followed by a space and then the filename
206which you have selected, for example ``text''.
207When you have completed the command,
208press carriage return and wait for edit's response:
209.DS I 1i
210% \fBedit text\fP \fI(followed by a carriage return)\fR
211"text" No such file or directory
212:
213.DE
214If you typed the command correctly,
215you will now be in communication with edit.
216Edit has set aside a buffer for use as
217a temporary working space during your current editing session.
218It also checked to see if the file you named, ``text'',
219already existed.
220As we expected, it was unable to find such a file
221since ``text'' is the name of the new file that we will create.
222Edit confirms this with the line:
223.DS I 1i
224"text" No such file or directory
225.DE
226On the next line appears edit's prompt ``:'',
227announcing that edit expects a command from you.
228You may now begin to create the new file.
229.SH
230The ``not found'' message
231.PP
232If you misspelled edit by typing, say, ``editor'',
233your request would be handled as follows:
234.DS I 1i
235% \fBeditor\fP
236editor: not found
237%
238.DE
239Your mistake in calling edit ``editor'' was
240treated by \s-2UNIX\s0 as a request
241for a program named ``editor''.
242Since there is no program
243named ``editor'',
244\s-2UNIX\s0 reported that the program was ``not found''.
245A new % indicates that \s-2UNIX\s0 is ready for another command,
246so you may enter the correct command.
247.SH
248A summary
249.PP
250Your exchange with \s-2UNIX\s0 as you logged in and made contact with edit
251should look something like this:
252.DS I 1i
253:login: \fBsusan\fP
254Password:
255Computer Center \s-2UNIX\s0 System
256\&... A Message of General Interest ...
257% \fBedit text\fP
258"text" No such file or directory
259:
260.DE
261.SH
262Entering text
263.PP
264You may now begin to enter text into the buffer.
265This is done by \fIappending\fP text to whatever
266is currently in the buffer.
267Since there is nothing in the buffer at the moment,
268you are appending text to nothing; in effect, you
269are creating text.
270Most edit commands have two forms:
271a word which describes what the command does
272and a shorter abbreviation of that word.
273Either form may be used.
274Many beginners find the full command names
275easier to remember,
276but once you are familiar with editing you may
277prefer to type the shorter abbreviations.
278The command to input text is ``append''
279which may be abbreviated ``a''.
280Type
281.B append
282and press carriage return.
283.DS I 1i
284% \fBedit text
285\fR:\|\fBappend
286.R
287.DE
288.SH
289.bd I 3
290Messages from
291.I edit
292.fl
293.bd I
294.PP
295If you make a mistake in entering a command and
296type something that edit does not recognize,
297edit will respond with a message
298intended to help you diagnose your error.
299For example, if you misspell the command to input text by typing,
300perhaps, ``add'' instead of ``append'' or ``a'',
301you will receive this message:
302.DS I 1i
303:\|\fBadd\fR
304add: Not an editor command
305:
306.DE
307When you receive a diagnostic message,
308check what you typed in order to determine what
309part of your command confused edit.
310The message above means that edit
311was unable to recognize your mistyped command
312and, therefore, did not execute it.
313Instead, a new ``:''
314appeared to let you know that
315edit is again ready to execute a command.
316.SH
317Text input mode
318.PP
319By giving the command ``append'' (or using the abbreviation ``a''),
320you entered
321.I
322text input mode,
323.R
324also known as
325.I
326append mode.
327.R
328When you enter text input mode,
329edit responds by doing nothing.
330You will not receive any prompts
331while in text input mode.
332This is your signal
333that you are to begin entering lines of text. You can enter
334pretty much anything you want on the lines. The
335lines are transmitted one by one to the buffer
336and held there during the editing session.
337You may append as much text as you want, and
338.I
339when you wish to stop entering text lines you should
340type a period as the only character on the line
341and press carriage return.
342.R
343When you give this signal that you want to stop appending text,
344you will exit from text input mode and reenter command mode.
345Edit will again
346prompt you for a command by printing ``:''.
347.PP
348Leaving append mode does not destroy the text in
349the buffer. You have to leave append
350mode to do any of the other kinds of editing,
351such as changing, adding, or printing text.
352If you type a period as the first character and
353type any other character on the same line,
354edit will believe you want to remain in append mode
355and will not let you out.
356As this can be very frustrating,
357be sure to type
358.B only
359the period and carriage return.
360.PP
361This is as good a place as any to learn an important
362lesson about computers and text: a blank space is
363a character as far as a computer is concerned.
364If you so much as type a period followed by a blank
365(that is, type a period and then the space bar on the keyboard),
366you will remain in append mode with the last line of text
367being:
368.DS I 1i
369.B
370.ps +2
371\&.
372.ps -2
373.R
374.DE
375Let's say that the lines of text you enter are
376(try to type
377.B exactly
378what you see, including ``thiss''):
379.DS I 1i
380.B
381This is some sample text.
382And thiss is some more text.
383Text editing is strange, but nice.
384\&.
385.R
386.DE
387The last line is the period followed by a carriage return
388that gets you out of append mode.
389If while typing the line you hit an incorrect key,
390recall that
391you may delete the incorrect character
392or cancel the entire line of input by erasing in the usual way.
393Refer to ``Communicating with \s-2UNIX\s0'' if you need to review
394the procedures for making a correction.
395Erasing a character or cancelling a line must be done
396before the line has been completed by a carriage return.
397We will discuss changes in lines already typed in session 2.
398.SH
399Writing text to disk
400.PP
401You are now ready to edit the text. The simplest kind of editing
402is to write it to disk as a file for safekeeping
403after the session is over.
404This is the only way to save information from one session to the next,
405since the editor's buffer is temporary and will last only until the
406end of the editing session.
407Thus, learning how to write a file to disk is second in
408importance only to entering the text.
409To write the contents of the buffer to a disk
410file, use the command ``write''
411(or its abbreviation ``w''):
412.DS I 1i
413:\|\fBwrite
414.R
415.DE
416Edit will copy the buffer to a disk file.
417If the file does not yet exist,
418a new file will be created automatically
419and the presence of a ``[New file]'' will be noted.
420The newly-created file will be given the name specified when
421you entered the editor, in this case ``text''.
422To confirm that the disk file has been successfully written,
423edit will repeat the filename and give
424the number of lines and the total
425number of characters in the file.
426The buffer remains unchanged by the ``write'' command.
427All of the lines which were written to disk will still be
428in the buffer,
429should you want to modify or add to them.
430.PP
431Edit must have a filename to use before it can write a file.
432If you forgot to indicate the name of the file
433when you began the editing session,
434edit will print
435.DS I 1i
436No current filename
437.DE
438in response to your write command.
439If this happens, you can specify the filename in a new write command:
440.DS I 1i
441:\|\fBwrite text
442.R
443.DE
444After the ``write'' (or ``w'') type a space and then the name of the file.
445.SH
446Signing off
447.PP
448We have done enough for this first lesson on using the
449\s-2UNIX\s0 text editor, and are ready to quit the session with edit.
450To do this we type ``quit'' (or ``q'') and press carriage return:
451.DS I 1i
452:\|\fBwrite
453.R
454"text" [New file] 3 lines, 90 characters
455:\|\fBquit\fR
456%
457.DE
458The % is from \s-2UNIX\s0 to tell you that your session with edit is
459over and you may command \s-2UNIX\s0 further. Since we want
460to end the entire session at the terminal we also need to
461exit from \s-2UNIX\s0.
462In response to the \s-2UNIX\s0 prompt of ``\|%\|''
463type a ``control d''. This is done by holding down the control
464key (usually labelled ``CTRL'') and simultaneously
465pressing the d key. This
466will end your session with \s-2UNIX\s0 and will ready the
467terminal for the next user.
468It is always important to type a ``control-d'' at the end of a session
469to make absolutely sure no one
470could accidentally stumble into your abandoned
471session and thus gain access to your files,
472tempting even the most honest of souls.
473.PP
474This is the end of the first session on \s-2UNIX\s0 text editing.
475.bp
476.ND
477.TL
478Session 2
479.PP
480Login with \s-2UNIX\s0 as in the first session:
481.DS I 1i
482:login: \fBsusan\fP \fI(carriage return)\fR
483Password: \fI(give password and carriage return)\fR
484.if t .sp .2v
485.if n .sp 1
486Computer Center \s-2UNIX\s0 System
487%
488.DE
489This time when you say that you want to edit,
490you can specify the name of the file you worked on last time.
491This will
492start edit working and it will fetch the contents of the
493file into the buffer, so that you can resume editing the same file.
494When edit has copied the file into the buffer, it
495will repeat its name and tell
496you the number of lines and characters it contains.
497Thus,
498.DS I 1i
499.B
500% edit text
501.R
502"text" 3 lines, 90 characters
503:
504.DE
505means you asked edit to fetch
506the file named ``text'' for editing,
507causing it to copy the
50890 characters of text into the buffer.
509Edit awaits
510your further instructions.
511In this session, we will append more text to our file,
512print the contents of the buffer, and learn to change the text of a line.
513.SH
514Adding more text to the file
515.PP
516If you want to add more to the end of your
517text you may do so by using the append command to enter text input mode.
518Here we'll use the abbreviation for the append command, ``a'':
519.DS I 1i
520:\|\fBa
521This is text added in Session 2.
522It doesn't mean much here, but
523it does illustrate the editor.
524\&.
525.R
526.DE
527.SH
528\ \ Interrupt
529.PP
530Should you press the \s-2RUBOUT\s+2 key (sometimes labelled \s-2DELETE\s+2)
531while working with edit,
532it will send this message to you:
533.DS I 1i
534Interrupt
535:
536.DE
537Any command that edit might be executing
538is terminated by rubout or delete,
539causing edit to prompt you for a new command.
540If you are appending text at the time,
541you will exit from append mode and be expected to give another command.
542The line of text that you were typing when the append command was interrupted
543will not be entered into the buffer.
544.SH
545Making corrections
546.PP
547If you have read a general introduction to \s-2UNIX\s0,
548such as ``Communicating with \s-2UNIX\s0'',
549you will recall that it is possible to erase individual
550letters that you have typed.
551This is done by typing the designated erase character,
552usually the number sign (#),
553as many times as there are characters you want to erase.
554If you make a bad start
555in a line
556and would like to begin again, this technique
557is cumbersome \- what if you had 15
558characters in your line and wanted to get rid of them?
559To do so either requires:
560.bd S 3
561.DS I 1i
562.B
563This is yukky tex###############
564.R
565.DE
566with no room for the great text you'd like to type, or,
567.DS I 1i
568.B
569This is yukky tex@This is great text.
570.R
571.fl
572.bd S
573.DE
574When you type the at-sign (@), you erase
575the entire line typed so far.
576You may immediately begin to retype the line.
577This, unfortunately, does not help after you type the
578line and press carriage return.
579To make corrections in lines which have been completed,
580it is necessary to use the editing commands
581covered in this session and those that follow.
582.SH
583Listing what's in the buffer
584.PP
585Having appended text to what you wrote in Lesson 1,
586you might be curious to see what is in the buffer.
587To print the contents of the buffer, type the command:
588.DS I 1i
589:\|\fB1,$p
590.R
591.DE
592The ``1'' stands for line 1 of the buffer,
593the ``$'' is a special symbol designating the last line
594of the buffer,
595and ``p'' (or \fBprint\fR) is the command to print from line 1
596to the end of the buffer. Thus,
597``1,$p''
598gives you:
599.DS I 1i
600This is some sample text.
601And thiss is some more text.
602Text editing is strange, but nice.
603This is text added in Session 2.
604It doesn't mean much here, but
605it does illustrate the editor.
606.DE
607Occasionally, you may
608enter into the buffer a character which can't be printed,
609which is done by striking a key while the \s-2CTRL\s0 key is depressed.
610In printing lines, edit uses a special notation to
611show the existence of non-printing characters.
612Suppose you had introduced the non-printing character ``control-a''
613into the word ``illustrate''
614by accidently holding down the \s-2CTRL\s0 key while
615typing ``a''.
616Edit would display
617.DS I 1i
618it does illustr^Ate the editor.
619.DE
620if you asked to have the line printed.
621To represent the control-a, edit shows ``^A''.
622The sequence ``^'' followed by a capital letter stands for the one character
623entered by holding down the \s-2CTRL\s0 key and typing the letter
624which appears after the ``^''.
625We'll soon discuss the commands which can be used
626to correct this typing error.
627.PP
628In looking over the text we see that
629``this'' is typed as ``thiss'' in the second line, as suggested.
630Let's correct the spelling.
631.SH
632Finding things in the buffer
633.PP
634In order to change something in the buffer we first need to
635find it. We can find ``thiss'' in the text we have
636entered by looking at a listing
637of the lines. Physically speaking, we search the lines
638of text looking for ``thiss'' and stop searching when
639we have found it.
640The way to tell edit to search for something
641is to type it inside slash marks:
642.DS I 1i
643:\|\fB/thiss/
644.R
645.DE
646By typing
647.B /thiss/
648and pressing carriage return edit is
649instructed to search for ``thiss''.
650If we asked edit to look for a pattern of characters
651which it could not find in the buffer,
652it would respond ``Pattern not found''.
653When edit finds
654the characters ``thiss'', it will print the line of text
655for your inspection:
656.DS I 1i
657And thiss is some more text.
658.DE
659Edit is now positioned in the buffer at the
660line which it just printed,
661ready to make a change in the line.
662.SH
663The current line
664.PP
665At all times during an editing session,
666edit keeps track of the line in the buffer where it is positioned.
667In general, the line which has been most recently
668printed, entered, or changed
669is considered to be the current position in the buffer.
670You can refer to your current position in the buffer by the
671symbol
672period (.) usually known by the name ``dot''.
673If you type ``.'' and carriage
674return you will be instructing edit to print the current line:
675.DS I 1i
676:\|\fB\s+2\&.\s-2
677.R
678And thiss is some more text.
679.DE
680.PP
681If you want to know the number of the current line,
682you can type
683.B \&.=
684and carriage return,
685and edit will respond with the line number:
686.DS I 1i
687:\|\fB\s+2.\s-2=
688.R
6892
690.DE
691If you type the number of any line and a carriage return,
692edit will
693position you at that line and
694print its contents:
695.DS I 1i
696:\|\fB2
697.R
698And thiss is some more text.
699.DE
700You should experiment with these commands to assure
701yourself that you understand what they do.
702.SH
703Numbering lines (nu)
704.PP
705The
706.B
707number (nu)
708.R
709command is similar to print,
710giving both the number and the text of each printed line.
711To see the number and the text of the current line type
712.DS I 1i
713:\|\fBnu
714.R
715\0\0\0\0\02\0\0And thiss is some more text.
716.DE
717Notice that the shortest abbreviation for the number command is
718``nu'' (and not ``n'' which is used for a different command).
719You may specify a range of lines
720to be listed by the number command in the same way that lines
721are specified for print.
722For example, ``1,$nu'' lists all lines in the buffer with the
723corresponding line numbers.
724.SH
725Substitute command (s)
726.PP
727Now that we have found our misspelled word it is
728time to change it from ``thiss'' to ``this''.
729As far as edit is concerned,
730changing things is a matter of
731substituting one thing for another.
732As
733.I a
734stood for
735.I append,
736so
737.I s
738stands for
739.I substitute.
740We will use the abbreviation ``s'' to reduce the chance
741of mistyping the substitute command.
742This command will instruct edit to make the change:
743.DS I 1i
7442s/thiss/this/
745.DE
746We first indicate the line to be changed, line 2,
747and then
748type an ``s'' to indicate we want
749substitution.
750Inside the first set of slashes
751are the characters that we want to change,
752followed by the characters to replace them
753and then a closing slash mark.
754To summarize:
755.DS I 1i
7562s/ \fIwhat is to be changed\fR / \fIwhat to change to \fR/
757.DE
758If edit finds an exact match of the characters to be
759changed it will make the change
760.B only
761in the first occurrence of
762the characters.
763If it does not find the characters
764to be changed it will respond:
765.DS I 1i
766Substitute pattern match failed
767.DE
768indicating your instructions could not be carried out.
769When edit does find the characters which you want to change,
770it will make the substitution and automatically print
771the changed line, so that you can check that the correct substitution
772was made.
773In the example,
774.DS I 1i
775:\|\fB2s/thiss/this/
776.R
777And this is some more text.
778:
779.DE
780line 2 (and line 2 only) will be searched for the characters
781``thiss'', and when the first exact match is found, ``thiss''
782will be changed to ``this''.
783Strictly speaking, it was not necessary above to
784specify the number of the line to be changed.
785In
786.DS I 1i
787:\|\fBs/thiss/this/
788.R
789.DE
790edit will assume that we mean to change
791the line where we are currently positioned
792(``.'').
793In this case,
794the command without a line number would have produced the same result
795because we were already positioned
796at the line we wished to change.
797.PP
798For another illustration of substitution
799we may choose the line:
800.DS I 1i
801Text editing is strange, but nice.
802.DE
803We might like to be a bit more positive. Thus, we could
804take out the characters ``strange, but\ '' so the line
805would read:
806.DS I 1i
807Text editing is nice.
808.DE
809A command which will first position edit at that line
810and then make the substitution is:
811.DS I 1i
812:\|\fB/strange/s/strange, but //
813.R
814.DE
815.PP
816What we have done here is combine our search with
817our substitution.
818Such combinations are perfectly legal.
819This illustrates that we do not necessarily have to use
820line numbers to identify a line to edit.
821Instead, we may identify the line we want to change
822by asking edit to search for a specified pattern of letters
823which occurs in that line.
824The parts of the above command are:
825.in +1i
826.TS
827.nr 35 \n(.u
828.nf
829.ds #d .d
830.if \(ts\n(.z\(ts\(ts .ds #d nl
831.nr 80 0
832.nr 38 \w\ 2\f3/strange/\fP\ 2
833.if \n(80<\n(38 .nr 80 \n(38
834.nr 38 \w\ 2\f3s\fP\ 2
835.if \n(80<\n(38 .nr 80 \n(38
836.nr 38 \w\ 2\f3/strange, but //\fP\ 2
837.if \n(80<\n(38 .nr 80 \n(38
838.nr 81 0
839.nr 38 \w\ 2tells edit to find the characters ``strange'' in the text\ 2
840.if \n(81<\n(38 .nr 81 \n(38
841.nr 38 \w\ 2tells edit we want to make a substitution\ 2
842.if \n(81<\n(38 .nr 81 \n(38
843.nr 38 \w\ 2substitutes nothing at all for the characters ``strange, but ''\ 2
844.if \n(81<\n(38 .nr 81 \n(38
845.nr 38 1n
846.nr 79 0
847.nr 40 \n(79+(0*\n(38)
848.nr 80 +\n(40
849.nr 41 \n(80+(3*\n(38)
850.nr 81 +\n(41
851.nr TW \n(81
852.if t .if (\n(TW+\n(.o)>7.75i .tm Table at line 307 file ed2.tbl is too wide - \n(TW units
853.fc \ 2 \ 3
854.nr #T 0
855.eo
856.de T#
857.ds #d .d
858.if \(ts\n(.z\(ts\(ts .ds #d nl
859.mk ##
860.nr ## -1v
861..
862.ec
863.ta \n(80u \n(81u
864\&\h'|\n(40u'\ 2\f3/strange/\fP\ 3\ 2\h'|\n(41u'\ 2tells edit to find the characters ``strange'' in the text\ 3\ 2
865.ta \n(80u \n(81u
866\&\h'|\n(40u'\ 2\f3s\fP\ 3\ 2\h'|\n(41u'\ 2tells edit we want to make a substitution\ 3\ 2
867.ta \n(80u \n(81u
868\&\h'|\n(40u'\ 2\f3/strange, but //\fP\ 3\ 2\h'|\n(41u'\ 2substitutes nothing at all for the characters ``strange, but ''\ 3\ 2
869.fc
870.nr T. 1
871.T# 1
872.if \n(35>0 .fi
873.TE
874.in -1i
875.PP
876You should note the space after ``but'' in ``/strange, but /''.
877If you do not indicate the space is to be taken out,
878your line will be:
879.DS I 1i
880.if t Text editing is nice.
881.if n Text editing is nice.
882.DE
883which looks a little funny
884because of the extra space between ``is'' and ``nice''.
885Again, we realize from this that a blank space
886is a real character to a computer, and in editing text
887we need to be aware of spaces
888within a line just as we would be aware of an ``a'' or
889a ``4''.
890.SH
891Another way to list what's in the buffer (z)
892.PP
893Although the print command is useful for looking at specific lines
894in the buffer,
895other commands can be more convenient for
896viewing large sections of text.
897You can ask to see a screen full of text at a time
898by using the command
899.B z.
900If you type
901.DS I 1i
902:\|\fB1z
903.R
904.DE
905edit will start with line 1 and continue printing lines,
906stopping either when the screen of
907your terminal is full
908or when the last line in the buffer has been printed.
909If you want to read the next segment of text, give the command
910.DS I 1i
911:\|\fBz
912.DE
913If no starting line number is given for the z command,
914printing will start at the ``current'' line, in this case the
915last line printed.
916Viewing lines in the buffer one screen full at a time
917is known as paging.
918Paging can also be used to print a section of text on a hard-copy terminal.
919.SH
920Saving the modified text
921.PP
922This seems to be a good place to pause in our work,
923and so we should end the second session.
924If you (in haste) type ``q'' to quit the session
925your dialogue with edit will be:
926.DS I 1i
927:\|\fBq
928.R
929No write since last change (q! quits)
930:
931.DE
932This is edit's warning that you have not written
933the modified contents of the buffer to disk.
934You run the risk of losing the work you have done
935during the editing session since the latest write
936command. Since in this lesson we have not written
937to disk at all, everything we have done
938would be lost.
939If we did not want to save the work done during
940this editing session, we would have to type ``q!''
941to confirm that we indeed wanted to end the session
942immediately, losing the contents of the buffer.
943However,
944since we want to preserve what
945we have edited, we need to say:
946.DS I 1i
947:\|\fBw
948.R
949"text" 6 lines, 171 characters
950.DE
951and then,
952.DS I 1i
953:\|\fBq
954% \fI{control d}\fR
955.DE
956and hang up the phone or turn off the terminal when
957\s-2UNIX\s0 asks for a name.
958This is the end of the second session on \s-2UNIX\s0 text editing.
959.bp
960.ND
961.TL
962Session 3
963.SH
964Bringing text into the buffer (e)
965.PP
966Login to \s-2UNIX\s0 and make contact with edit.
967You should try to login without
968looking at the notes, but if you must
969then by all means do.
970.PP
971Did you remember to give the name of the file
972you wanted to edit? That is, did you say
973.DS I 1i
974% \fBedit text\fR
975.DE
976or simply
977.DS I 1i
978% \fBedit\fR
979.DE
980Both ways get you in contact with edit, but the first way
981will bring a copy of the file named ``text'' into
982the buffer.
983If you did forget to tell edit the name of your file,
984you can get it into the buffer by
985saying:
986.DS I 1i
987:\|\fBe text
988.R
989"text" 6 lines, 171 characters
990.DE
991The command
992.B edit,
993which may be abbreviated ``\fBe\fR'',
994tells edit that you want
995to erase anything that might already be in
996the buffer and bring a copy of the file ``text'' into the buffer
997for editing.
998You may also use the edit (e) command to change files in
999the middle of an editing session
1000or to give edit the name of a new file that you want to create.
1001Because the edit command clears the buffer,
1002you will receive a warning if you try to edit a new file without
1003having saved a copy of the old file.
1004This gives you a chance to write the contents of the buffer to disk
1005before editing the next file.
1006.SH
1007Moving text in the buffer (m)
1008.PP
1009Edit allows you to move lines of text
1010from one location in the buffer to another
1011by means of the
1012.B move
1013(\fBm\fR) command:
1014.DS I 1i
1015:\|\fB2,4m$
1016.R
1017.DE
1018This command directs edit to move lines 2, 3, and 4
1019to the end of the buffer ($).
1020The format for the move command is that you specify
1021the first line to be moved, the last line to be moved,
1022the move command ``m'', and the line after which
1023the moved text is to be placed.
1024Thus,
1025.DS I 1i
1026:\|\fB1,6m20
1027.R
1028.DE
1029would instruct edit to move lines 1 through 6 (inclusive)
1030to a position after line 20 in the buffer.
1031To move only one line, say, line 4,
1032to a position in the buffer after line 6,
1033the command would be ``4m6''.
1034.PP
1035Let's move some text using the command:
1036.DS I 1i
1037:\|\fB5,$m1
1038.R
10392 lines moved
1040it does illustrate the editor.
1041.DE
1042After executing a command which changes more than one line of the buffer,
1043edit tells how many lines were affected by the change.
1044The last moved line is printed for your inspection.
1045If you want to see more than just the last line,
1046use the print (p), z, or number (nu) command to view more text.
1047The buffer should now contain:
1048.DS I 1i
1049This is some sample text.
1050It doesn't mean much here, but
1051it does illustrate the editor.
1052And this is some more text.
1053Text editing is nice.
1054This is text added in Session 2.
1055.DE
1056We can restore the original order by typing:
1057.DS I 1i
1058:\|\fB4,$m1
1059.R
1060.DE
1061or, combining context searching and the move command:
1062.DS I 1i
1063:\|\fB/And this is some/,/This is text/m/This is some sample/
1064.R
1065.DE
1066The problem with combining context searching
1067with the move command
1068is that the chance of making a typing error
1069in such a long command is greater than
1070if one types line numbers.
1071.SH
1072Copying lines (copy)
1073.PP
1074The
1075.B copy
1076command
1077is used to make a second copy of specified lines,
1078leaving the original lines where they were.
1079Copy
1080has the same format as the move command, for example:
1081.DS I 1i
1082:\|\fB12,15copy $
1083.R
1084.DE
1085makes a copy of lines 12 through 15,
1086placing the added lines after the buffer's end ($).
1087Experiment with the copy command
1088so that you can become familiar with how it works.
1089Note that the shortest abbreviation for copy is
1090``co'' (and
1091.B not
1092the letter ``c'' which has another meaning).
1093.SH
1094Deleting lines (d)
1095.PP
1096Suppose you want to delete
1097the line
1098.DS I 1i
1099This is text added in Session 2.
1100.DE
1101from the buffer.
1102If you know the number of the line to be deleted,
1103you can type
1104that number followed by
1105``\fBdelete\fR'' or ``\fBd\fR''.
1106This example deletes line 4:
1107.DS I 1i
1108:\|\fB4d
1109.R
1110It doesn't mean much here, but
1111.DE
1112Here ``4'' is the number of the line to be deleted and
1113``delete'' or ``d'' is the command to delete the line.
1114After executing the delete command,
1115edit prints the line which has become the current line (``.'').
1116.PP
1117If you do not happen to know the line number
1118you can search for the line and then delete it using this
1119sequence of commands:
1120.DS I 1i
1121:\|\fB/added in Session 2./
1122.R
1123This is text added in Session 2.
1124:\|\fBd
1125.R
1126It doesn't mean much here, but
1127.DE
1128The ``/added in Session 2./''
1129asks edit to locate and print
1130the next line which contains the indicated text.
1131Once you are sure that you have correctly specified the line that
1132you want to delete,
1133you can enter the delete (d) command.
1134In this case it is not necessary to
1135specify a line number before the ``d''.
1136If no line number is given,
1137edit deletes the current line (``.''),
1138that is, the line found by our search.
1139After the deletion, your buffer should contain:
1140.DS I 1i
1141This is some sample text.
1142And this is some more text.
1143Text editing is nice.
1144It doesn't mean much here, but
1145it does illustrate the editor.
1146.DE
1147To delete both lines 2 and 3:
1148.DS I 1i
1149And this is some more text.
1150Text editing is nice.
1151.DE
1152you type
1153.DS I 1i
1154:\|\fB2,3d
1155.R
1156.DE
1157which specifies the range of lines from 2 to 3,
1158and the operation on those lines \- ``d'' for delete.
1159.PP
1160Again, this presumes that you know the line numbers for
1161the lines to be deleted.
1162If you do not you might combine the search command
1163with the delete command as so:
1164.DS I 1i
1165:\|\fB/And this is some/,/Text editing is nice./d
1166.R
1167.DE
1168.SH
1169A word or two of caution:
1170.PP
1171In using the search function to locate lines to
1172be deleted you should be
1173.B
1174absolutely sure
1175.R
1176the characters you give as the basis for the search
1177will take edit to the line you want deleted.
1178Edit will search for the first
1179occurrence of the characters starting from where
1180you last edited \-
1181that is, from the line you see printed if you type dot (.).
1182.PP
1183A search based on too few
1184characters may result in the wrong lines being deleted,
1185which edit will do as easily as if you had meant it.
1186For this reason, it is usually safer
1187to specify the search and then delete in two separate steps,
1188at least until you become familiar enough with using the editor
1189that you understand how best to specify searches.
1190For a beginner it is not a bad idea to double-check
1191each command before pressing carriage return to send the command on its way.
1192.SH
1193Undo (u) to the rescue
1194.PP
1195The
1196.B
1197undo (u)
1198.R
1199command has the ability to
1200reverse the effects of the last command.
1201To undo the previous command, type
1202``u'' or ``undo''.
1203Undo can rescue
1204the contents of the buffer from many an unfortunate mistake.
1205However, its powers are not unlimited,
1206so it is still wise to be reasonably careful about the commands you give.
1207It is possible to undo only commands which
1208have the power to change the buffer, for example
1209delete, append, move, copy, substitute, and even undo itself.
1210The commands write (w) and edit (e) which interact with disk files
1211cannot be undone, nor can commands such as print which do not change
1212the buffer.
1213Most importantly,
1214the
1215.B only
1216command which can be reversed by undo
1217is the
1218last ``undo-able'' command which you gave.
1219.PP
1220To illustrate,
1221let's issue an undo command.
1222Recall that the last buffer-changing command we gave deleted
1223the lines which were formerly numbered 2 and 3.
1224Executing undo at this moment will reverse the effects
1225of the deletion, causing those two lines to be
1226replaced in the buffer.
1227.DS I 1i
1228:\|\fBu
1229.R
12302 more lines in file after undo
1231And this is some more text.
1232.DE
1233Here again, edit informs you if the command affects more
1234than one line,
1235and prints
1236the text of the line which is now ``dot'' (the current line).
1237.SH
1238More about the dot (.) and buffer end ($)
1239.PP
1240The function assumed by the symbol dot depends on its context.
1241It can be used:
1242.IP
12431. to exit from append mode we type dot (and only a dot) on
1244a line and press carriage return;
1245.IP
12462. to refer to the line we are at in the buffer.
1247.LP
1248Dot can also be combined with the equal sign to get
1249the number of the line currently being edited:
1250.DS I 1i
1251:\|\fB\&.=
1252.R
1253.DE
1254Thus if we type ``\fB.\fR='' we are asking for the number of the line
1255and if we type ``\fB.\fR'' we are asking for the text of the line.
1256.PP
1257In this editing session and the last, we used the dollar
1258sign to indicate the end of the buffer
1259in commands such as print, copy, and move.
1260The dollar sign as a command asks edit to print the last
1261line in the buffer.
1262If the dollar sign is combined with the equal sign ($=)
1263edit will print the line number corresponding to the
1264last line in the buffer.
1265.PP
1266``\fB.\fR'' and ``$'' therefore represent line numbers.
1267Whenever appropriate, these symbols can be used in
1268place of line numbers in commands.
1269For example
1270.DS I 1i
1271:\|\fB\s+2.\s-2,$d
1272.R
1273.DE
1274instructs edit to delete all lines from the current line (\fB.\fR)
1275to the end of the buffer.
1276.SH
1277Moving around in the buffer (+ and \-)
1278.PP
1279It is frequently convenient during an editing session
1280to go back and re-read a previous line.
1281We could specify a context search for a line we want to
1282read if we remember some of its text,
1283but if we simply want to see what was written a few, say 3, lines
1284ago, we can type
1285.DS I 1i
1286\-3p
1287.DE
1288This tells edit to move back to a position 3 lines
1289before the current line (.)
1290and print that line.
1291We can move forward in the buffer similarly:
1292.DS I 1i
1293+2p
1294.DE
1295instructs edit to print the line which is 2
1296ahead of our current position.
1297.PP
1298You may use ``+'' and ``\-'' in any command where edit
1299accepts line numbers.
1300Line numbers specified with ``+'' or ``\-''
1301can be combined to print a range of lines.
1302The command
1303.DS I 1i
1304:\|\fB\-1,+2copy$
1305.R
1306.DE
1307makes a copy of 4 lines: the current line, the line before it,
1308and the two after it.
1309The copied lines will be placed after the last line
1310in the buffer ($).
1311.PP
1312Try typing only ``\-''; you will move back one line just as
1313if you had typed ``\-1p''.
1314Typing the command ``+'' works similarly.
1315You might also try typing a few plus or minus signs in a row
1316(such as ``+++'') to see edit's response.
1317Typing a carriage return alone on a line is the equivalent
1318of typing ``+1p''; it will move you one line ahead in the buffer
1319and print that line.
1320.PP
1321If you are at the last line of the buffer and try
1322to move further ahead, perhaps by typing a ``+'' or
1323a carriage return alone on the line,
1324edit will remind you that you are at the end of the buffer:
1325.DS I 1i
1326At end-of-file
1327.DE
1328Similarly, if you try to move to a position before the first line,
1329edit will print one of these messages:
1330.DS I 1i
1331Nonzero address required on this command
1332Negative address \- first buffer line is 1
1333.DE
1334The number associated with a buffer line is the line's ``address'',
1335in that it can be used to locate the line.
1336.SH
1337Changing lines (c)
1338.PP
1339There may be occasions when you want to delete certain lines and
1340insert new text in their place.
1341This can be accomplished easily with the
1342.B "change (c)"
1343command.
1344The change command instructs edit to delete specified lines
1345and then switch to text input mode in order to
1346accept the text which will replace them.
1347Let's say we want to change the first two lines in the buffer:
1348.DS I 1i
1349This is some sample text.
1350And this is some more text.
1351.DE
1352to read
1353.DS I 1i
1354This text was created with the \s-2UNIX\s0 text editor.
1355.DE
1356To do so, you can type:
1357.DS I 1i
1358:\|\fB1,2c
1359.R
13602 lines changed
1361.B
1362This text was created with the \s-2UNIX\s0 text editor.
1363\s+2\&.\s-2
1364.R
1365:
1366.DE
1367In the command
1368.B 1,2c
1369we specify that we want to change
1370the range of lines beginning with 1 and ending with 2
1371by giving line numbers as with the print command.
1372These lines will be deleted.
1373After a carriage return enters the change command,
1374edit notifies you if more than one line will be changed
1375and places you in text input mode.
1376Any text typed on the following lines will be inserted into
1377the position where lines were deleted by the change command.
1378You will remain in text input mode until you exit in the usual way,
1379by typing a period alone on a line.
1380Note that the number of lines added to the buffer need not be
1381the same as the number of lines deleted.
1382.sp 1
1383.PP
1384This is the end of the third session on text editing with \s-2UNIX\s0.
1385.bp
1386.ND
1387.TL
1388Session 4
1389.PP
1390This lesson covers several topics, starting with
1391commands which apply throughout the buffer,
1392characters with special meanings,
1393and how to issue \s-2UNIX\s0 commands while in the editor.
1394The next topics deal with files:
1395more on reading and writing,
1396and methods of recovering files lost in a crash.
1397The final section suggests sources of further information.
1398.SH
1399Making commands global (g)
1400.PP
1401One disadvantage to the commands we have used for
1402searching or substituting is that if you
1403have a number of instances of a word to change
1404it appears that you have to type the command
1405repeatedly, once for
1406each time the change needs to be made.
1407Edit, however, provides a way to make commands
1408apply to the entire contents of the buffer \-
1409the
1410.B
1411global (g)
1412.R
1413command.
1414.PP
1415To print all lines
1416containing a certain sequence of characters
1417(say, ``text'')
1418the command is:
1419.DS I 1i
1420:\|\fBg/text/p
1421.R
1422.DE
1423The ``g'' instructs edit to
1424make a global search for all lines
1425in the buffer containing the characters ``text''.
1426The ``p'' prints the lines found.
1427.PP
1428To issue a global command, start by typing a ``g'' and then a search
1429pattern identifying
1430the lines to be affected.
1431Then, on the same line, type the command to be
1432executed on the identified lines.
1433Global substitutions are frequently useful.
1434For example,
1435to change all instances of the word ``text'' to the word ``material''
1436the command would be a combination of the global search and the
1437substitute command:
1438.DS I 1i
1439:\|\fBg/text/s/text/material/g
1440.R
1441.DE
1442Note the ``g'' at the end of the global command
1443which instructs edit to change
1444each and every instance of ``text'' to ``material''.
1445If you do not type the ``g'' at the end of the command
1446only the
1447.I first
1448instance of ``text'' in each line will be changed
1449(the normal result of the substitute command).
1450The ``g'' at the end of the command is independent of the ``g''
1451at the beginning.
1452You may give a command such as:
1453.DS I 1i
1454:\|\fB14s/text/material/g
1455.R
1456.DE
1457to change every instance of ``text'' in line 14 alone.
1458Further, neither command will change ``Text'' to ``material''
1459because ``Text'' begins with a capital rather than a lower-case
1460.I t.
1461.PP
1462Edit does not automatically print the lines modified by a
1463global command.
1464If you want the lines to be printed, type a ``p''
1465at the end of the global command:
1466.DS I 1i
1467:\|\fBg/text/s/text/material/gp
1468.R
1469.DE
1470The usual qualification should be made
1471about using the global command in combination with any other \-
1472in essence, be sure of what you are telling edit to do
1473to the entire buffer. For example,
1474.DS I 1i
1475:\|\fBg/ /d
1476.R
147772 less lines in file after global
1478.DE
1479will delete every line containing a blank anywhere in it.
1480This could adversely affect
1481your document, since most lines have spaces between words
1482and thus would be deleted.
1483After executing the global command,
1484edit will print a warning if the command added or deleted more than one line.
1485Fortunately, the undo command can reverse
1486the effects of a global command.
1487You should experiment with the global command
1488on a small buffer of text to see what it can do for you.
1489.SH
1490More about searching and substituting
1491.PP
1492In using slashes to identify a character string
1493that we want to search for or change,
1494we have always specified the exact characters.
1495There is a less tedious way to
1496repeat the same string of characters.
1497To change ``noun'' to ``nouns'' we may type either
1498.DS I 1i
1499:\|\fB/noun/s/noun/nouns/
1500.R
1501.DE
1502as we have done in the past,
1503or a somewhat abbreviated command:
1504.DS I 1i
1505:\|\fB/noun/s//nouns/
1506.R
1507.DE
1508In this example, the characters to be changed
1509are not specified \-
1510there are no characters, not even a space,
1511between the two slash marks which indicate what is to be changed.
1512This lack of characters between the slashes is taken by the editor to mean
1513``use the characters we last searched for as the characters to be changed.''
1514.PP
1515Similarly, the last context search may be repeated
1516by typing a pair of slashes with nothing between them:
1517.DS I 1i
1518:\|\fB/does/
1519.R
1520It doesn't mean much here, but
1521:\|\fB//
1522.R
1523it does illustrate the editor.
1524.DE
1525Because no characters are specified for the second search,
1526the editor scans the buffer for the next occurrence of the
1527characters ``does''.
1528.PP
1529Edit normally searches forward through the buffer,
1530wrapping around from the end of the buffer to the beginning,
1531until the specified character string is found.
1532If you want to search in the reverse direction,
1533use question marks (?) instead of slashes
1534to surround the character string.
1535.SH
1536Special characters
1537.PP
1538Two characters have special meanings when
1539used in specifying searches: ``$'' and ``^''.
1540``$'' is taken by the editor to mean ``end of the line''
1541and is used to identify strings
1542which occur at the end of a line.
1543.DS I 1i
1544:\|\fBg/ing$/s//ed/p
1545.R
1546.DE
1547tells the editor to search for all lines ending in ``ing''
1548(and nothing else, not even a blank space),
1549to change each final ``ing'' to ``ed''
1550and print the changed lines.
1551.PP
1552The symbol ``^'' indicates the beginning of a line.
1553Thus,
1554.DS I 1i
1555:\|\fBs/^/1. /
1556.R
1557.DE
1558instructs the editor to insert ``1.'' and a space at the beginning
1559of the current line.
1560.PP
1561The characters ``$'' and ``^'' have special meanings only in the context
1562of searching.
1563At other times, they are ordinary characters.
1564If you ever need to search for a character that has a special meaning,
1565you must indicate that the
1566character is to temporarily lose
1567its special significance by typing another special character,
1568the backslash (\\), before it.
1569.DS I 1i
1570:\|\fBs/\\\\\&$/dollar/
1571.R
1572.DE
1573looks for the character ``$'' in the current
1574line and replaces it by the word ``dollar''.
1575Were it not for the backslash, the ``$'' would have represented
1576``the end of the line'' in your search,
1577not necessarily the character ``$''.
1578The backslash retains its special significance at all times.
1579.SH
1580Issuing \s-2UNIX\s0 commands from the editor
1581.PP
1582After creating several files with the editor,
1583you may want to delete files
1584no longer useful to you or ask for a list of your files.
1585Removing and listing files are not functions of the editor,
1586and so they require the use of \s-2UNIX\s0 system commands
1587(also referred to as ``shell'' commands, as
1588``shell'' is the name of the program that processes \s-2UNIX\s0 commands).
1589You do not need to quit the editor to execute a \s-2UNIX\s0 command
1590as long as you indicate that it
1591is to be sent to the shell for execution.
1592To use the \s-2UNIX\s0 command
1593.I rm
1594to remove the file named ``junk'' type:
1595.DS I 1i
1596:\|\fB!rm junk
1597.R
1598!
1599:
1600.DE
1601The exclamation mark (!)
1602indicates that the rest of the line is to be processed as a \s-2UNIX\s0 command.
1603If the buffer contents have not been written since the last change,
1604a warning will be printed before the command is executed.
1605The editor prints a ``!'' when the command is completed.
1606The tutorial ``Communicating with \s-2UNIX\s0''
1607describes useful features of the system,
1608of which the editor is only one part.
1609.SH
1610Filenames and file manipulation
1611.PP
1612Throughout each editing session,
1613edit keeps track of the name of the file being edited as the
1614.I "current filename."
1615Edit remembers as the current filename the name given
1616when you entered the editor.
1617The current filename changes whenever the edit (e) command
1618is used to specify a new file.
1619Once edit has recorded a current filename,
1620it inserts that name into any command where a filename has been omitted.
1621If a write command does not specify a file,
1622edit, as we have seen, supplies the current filename.
1623You can have the editor write onto a different file
1624by including its name in the write command:
1625.DS I 1i
1626:\fB\|w chapter3
1627.R
1628"chapter3" 283 lines, 8698 characters
1629.DE
1630The current filename remembered by the editor
1631.I
1632will not be changed as a result of the write command
1633unless it is the first filename given in the editing session.
1634.R
1635Thus, in the next write command
1636which does not specify a name,
1637edit will write onto the current file and not onto the file ``chapter3''.
1638.SH
1639The file (f) command
1640.PP
1641To ask for the current filename, type
1642.B file
1643(or
1644.B f ).
1645In response, the editor provides current information about the buffer,
1646including the filename, your current position, and the number of
1647lines in the buffer:
1648.DS I 1i
1649:\|\fBf
1650.R
1651"text" [Modified] line 3 of 4 --75%--
1652.DE
1653.\"The expression ``[Edited]'' indicates that the buffer contains
1654.\"either the editor's copy of the existing file ``text''
1655.\"or a file which you are just now creating.
1656If the contents of the buffer have changed
1657since the last time the file was written,
1658the editor will tell you that the file has been ``[Modified]''.
1659After you save the changes by writing onto a disk file,
1660the buffer will no longer be considered modified:
1661.DS I 1i
1662:\|\fBw
1663.R
1664"text" 4 lines, 88 characters
1665:\|\fBf
1666.R
1667"text" line 3 of 4 --75%--
1668.DE
1669.SH
1670Reading additional files (r)
1671
1672.PP
1673The
1674.B
1675read (r)
1676.R
1677command allows you to add the contents of a file
1678to the buffer
1679without destroying the text already there.
1680To use it, specify the line after which the new text will be placed,
1681the command
1682.I r,
1683and then the name of the file.
1684.DS I 1i
1685:\|\fB$r bibliography
1686.R
1687"bibliography" 18 lines, 473 characters
1688.DE
1689This command reads in the file
1690.I bibliography
1691and adds it to the buffer after the last line.
1692The current filename is not changed by the read command unless
1693it is the first filename given in the editing session.
1694.SH
1695Writing parts of the buffer
1696.PP
1697The
1698.B
1699write (w)
1700.R
1701command can write all or part of the buffer
1702to a file you specify.
1703We are already familiar with
1704writing the entire contents of the
1705buffer to a disk file.
1706To write only part of the buffer onto a file,
1707indicate the beginning and ending lines before the write command,
1708for example
1709.DS I 1i
1710:\|\fB45,$w ending
1711.R
1712.DE
1713Here all lines from 45 through the end of the buffer
1714are written onto the file named
1715.I ending.
1716The lines remain in the buffer
1717as part of the document you are editing,
1718and you may continue to edit the entire buffer.
1719.SH
1720Recovering files
1721.PP
1722Under most circumstances,
1723edit's crash recovery mechanism
1724is able to save work to within a few lines of changes
1725after a crash or if the phone is hung up accidently.
1726If you lose the contents of an editing buffer in a system crash,
1727you will normally receive mail when you login which gives
1728the name of the recovered file.
1729To recover the file,
1730enter the editor and type the command
1731.B recover
1732(\fBrec\fR),
1733followed by the name of the lost file.
1734.DS I 1i
1735.R
1736:\|\fBrecover chap6
1737.R
1738.DE
1739Recover is sometimes unable to save the entire buffer successfully,
1740so always check the contents of the saved buffer carefully
1741before writing it back onto the original file.
1742.SH
1743Other recovery techniques
1744.PP
1745If something goes wrong when you are using the editor,
1746it may be possible to save your work by using the command
1747.B preserve
1748(\fBpre\fR),
1749which saves the buffer as if the system had crashed.
1750If you are writing a file and you get the message
1751``Quota exceeded'', you have tried to use more disk storage
1752than is allotted to your account.
1753.I
1754Proceed with caution
1755.R
1756because it is likely that only a part
1757of the editor's buffer is now present in the file you tried to write.
1758In this case you should use the shell escape from the editor (!)
1759to remove some files you don't need and try to write
1760the file again.
1761If this is not possible and you cannot find someone to help you,
1762enter the command
1763.DS I 1i
1764:\|\fBpreserve
1765.R
1766.DE
1767and then seek help.
1768Do not simply leave the editor.
1769If you do, the buffer will be lost,
1770and you may not be able to save your file.
1771After a preserve, you can use the recover command
1772once the problem has been corrected.
1773.PP
1774If you make an undesirable change to the buffer
1775and issue a write command before discovering your mistake,
1776the modified version will replace any previous version of the file.
1777Should you ever lose a good version of a document in this way,
1778do not panic and leave the editor.
1779As long as you stay in the editor,
1780the contents of the buffer remain accessible.
1781Depending on the nature of the problem,
1782it may be possible
1783to restore the buffer to a more complete
1784state with the undo command.
1785After fixing the damaged buffer, you can again write the file
1786to disk.
1787.SH
1788Further reading and other information
1789.PP
1790Edit is an editor designed for beginning and casual users.
1791It is actually a version of a more powerful editor called
1792.I ex.
1793These lessons are intended to introduce you to the editor
1794and its more commonly-used commands.
1795We have not covered all of the editor's commands,
1796just a selection of commands
1797which should be sufficient to accomplish most of your editing tasks.
1798You can find out more about the editor in the
1799.I
1800Ex Reference Manual,
1801.R
1802which is applicable to both
1803.I ex
1804and
1805.I edit.
1806The manual is available from the Computer Center Library,
1807218 Evans Hall.
1808One way to become familiar with the manual is to begin by reading
1809the description of commands that you already know.
1810.bd I 3
1811.SH
1812Using
1813.I ex
1814.fl
1815.bd I
1816.PP
1817As you become more experienced with using the editor,
1818you may still find that edit continues to meet your needs.
1819However, should you become interested in using ex,
1820it is easy to switch.
1821To begin an editing session with ex,
1822use the name
1823.B ex
1824in your command instead of
1825.B edit.
1826.PP
1827Edit commands work the same way in ex,
1828but the editing environment is somewhat different.
1829You should be aware of a few differences
1830that exist between the two versions of the editor.
1831In edit, only the characters ``^'', ``$'', and ``\\'' have
1832special meanings in searching the buffer
1833or indicating characters to be changed by a substitute command.
1834Several additional characters have ``magic''
1835meanings in ex, as described in the
1836.I
1837Ex Reference Manual.
1838.R
1839Another feature of the edit environment prevents users from
1840accidently entering two alternative modes of editing,
1841.I open
1842and
1843.I visual,
1844in which
1845the editor behaves quite differently than in normal command mode.
1846If you are using ex and the editor behaves strangely,
1847you may have accidently entered open mode by typing ``o''.
1848Type the \s-2ESC\s0 key and then a ``q''
1849to get out of open or visual mode and back into
1850the regular editor command mode.
1851The document
1852.I
1853An Introduction to Display Editing with Vi
1854.R
1855provides a full discussion of visual mode.
1856.sp 5
1857.bd I 3
1858.in +.7i
1859.ll -.7i
1860.nr LL -.7i
1861.LP
1862.I
1863This tutorial was produced at the Computer Center of the
1864University of California, Berkeley.
1865We welcome comments and suggestions concerning this item
1866and the \s-2UNIX\s0 documentation in general.
1867Contact the \s-2UNIX\s0 consultant in 217 Evans, 642-4072.
1868.fl
1869.bd I
1870.ND
1871.TL
1872Index
1873.sp 3
1874.2C
1875.nf
1876addressing, \fIsee\fR line numbers
1877append mode, 4
1878backslash (\\), 17
1879buffer, 1
1880command mode, 4
1881context search, 7, 9, 13, 17
1882control characters (``^'' notation), 7
1883control-d, 5
1884current filename, 18, 19
1885current line (.), 8, 14
1886diagnostic messages, 3
1887disk, 1
1888documentation, 20
1889edit (to begin editing session), 2, 6
1890editing commands:
1891.in +2
1892append (a), 3, 4, 6
1893change (c), 15
1894copy (co), 12
1895delete (d), 12-13
1896edit (e), 11
1897file (f), 18
1898global (g), 16-17
1899move (m), 11-12
1900number (nu), 8
1901preserve (pre), 19
1902print (p), 7
1903quit (q), 5, 10
1904quit! (q!), 10
1905read (r), 18-19
1906recover (rec), 19
1907substitute (s), 8-9, 16, 17
1908undo (u), 13, 17
1909write (w), 4-5, 10, 19
1910z, 9
1911.sp 10i
1912! (shell escape), 18
1913$= , 14
1914+, 14
1915\-, 14
1916//, 7, 17
1917??, 17
1918\&\fB.\fR, 8, 14
1919\&\fB.\fR=, 8, 14
1920.in -2
1921erasing
1922.ti +2
1923characters (#), 6
1924.ti +2
1925lines (@), 7
1926ex (text editor), 20
1927\fIEx Reference Manual\fR, 20
1928file, 1
1929file recovery, 19
1930filename, 1
1931Interrupt (message), 6
1932line numbers, \fIsee also\fR current line
1933.ti +2
1934dollar sign ($), 7, 14
1935.ti +2
1936dot (.), 8, 14
1937.ti +2
1938relative (+ and \-), 14
1939logging out, 5
1940login procedure, 2
1941``magic'' characters, 20
1942non-printing characters, 7
1943``not found'' (message), 3
1944program, 1
1945recovery \fIsee\fR file recovery
1946shell, 18
1947shell escape (!), 18
1948special characters (^, $, \e), 17
1949text input mode, 4
1950UNIX, 1