Tutorial

Introduction

This document describes how to use se, assuming you have not used it before. Se is a powerful, friendly, full-screen text editor. It runs on a number of different computers — in fact, one of the advantages of using se is that once you have learned it, you can use it on any of the computers you find it on. Some parts of this manual refer specifically to computers running the Unix operating system. The version of se described below follows the Unix pattern-matching conventions; if you are unsure whether this manual refers to the version that you have, consult a guru.

We assume that your computer is operational, and that you have access to se. If you need assistance, best see your local guru. We further assume that you know how to use the backspace key; which is usually found at the top right of the main part of the keyboard, and that you have some idea of what a “file” is.

Se is a very flexible editor; it is possible to modify its behaviour to suit the user. In this manual it is assumed that se is being used in its default configuration “straight out of the box”. If someone has been using it before you and has set it up to suit themselves, please ask them to restore se to its original condition.

Starting an Editing Session

The first step is to tell the computer that you want to use se. To do this, type:
$ se
and press return.
Throughout this guide, boldface is used to indicate information that you should type in. Things displayed by se are shown in the regular font.
You are now in the editor, ready to go. You should see a blank screen, except for a rule down the left-hand side, and a line at the bottom of the screen. (If your computer can display colour, the various parts of the screen will be shown in colours given below.)

The space in the left margin is used for information about lines; lines may have names or numbers which can appear in this margin. The (green) line at the bottom is known as the status line; it is used to display information about what the editor is doing — for example saving your work to disk. It also shows the time, and whether various options are switched on. The line above the status line is special; it is the command line, and is used for telling the editor what to do. The (red) command prompt ‘cmd>’ appears there. The text of documents which you are editing will appear (in white) in the large blank area of the screen.

At this point, se is waiting for instructions from you. You can instruct se by using “commands”, which are single letters (occasionally accompanied by other information, which you will see shortly).

Entering Text - the Append Command

The first thing that you will need is text to edit. Working with se is like working with a blank sheet of paper; you write on the paper, alter or add to what you have written, and either file the paper away for further use or throw it away. In se's terminology, the blank sheet of paper you start with is called the “buffer”. The buffer is empty when you start editing. All editing operations take place in the buffer; nothing you do can affect any file unless you make an explicit request to transfer the contents of the buffer to a file.

So how do you put text into the buffer? The “append” command is used to do this:

a
Note that this command and all other commands given to the editor must be in lower-case. Upper-case is used for line names, as we shall see later. This command appends (adds) text lines to the buffer, as they are typed in.

To put text into the buffer, simply type it in, terminating each line with a newline:

The quick brown fox
    jumps over
   the lazy dog.
.
To stop entering text, you must enter a line containing only a full stop, immediately followed by a newline, as in the last line above. This tells se that you are finished writing on the buffer, and are ready to do some editing.

The buffer now contains:

The quick brown fox
    jumps over
   the lazy dog.
Neither the append command nor the final full stop are included in the buffer — just the text you typed in between them.

Since the example above is very small, it fits easily on the screen. Se is actually capable of editing files of many thousands of lines and each line can be hundreds of characters long. Clearly, the screen is not big enough to show all of the file at once! We will see later how to move around a large file. For the moment, try the following experiment: start editing again and this time type in more lines of text — enough to reach the bottom of the screen. What happens when you type in even more text?

In fact, se will show you as much of the text as it can fit on your screen, but still remembers text that has disappeared. The commands we will learn about later will tell se which part of the file you are interested in and therefore which part to show on the screen.

Writing text on a file - the Write command

Now that you have some text in the buffer, you need to know how to save it. The write command ‘w’ is used for this purpose. It is used like this:
w file
where ‘file’ is the name of the file used to store what you just typed in. Se produces a message in the status line saying ‘writing’ when it is busy copying the information to the disk. (The message may appear and disappear too quickly to be seen on fast machines.) The write command copies the contents of the buffer to the named file, destroying whatever was previously in the file. The buffer, however, remains intact; whatever you typed in is still there. To indicate that the transfer of data was successful, se displays the number of lines written. In this example, se would say:
3
on the status line. It is advisable to write the contents of the buffer out to a file periodically, to ensure that you have an up-to-date version in case of some terrible catastrophe (like a system crash).

Finishing up - the Quit command

Now that you have saved your text in a file, you may wish to leave the editor. The “quit” command ‘q’ is provided for this:
q
The next thing you see should be the prompt from the shell. If you did not write out the contents of the buffer, the editor would respond ‘Buffer hasn't been saved’ on the status line. This is to remind you to write out the buffer, so that the results of your editing session are not lost. If you intended that the buffer be discarded, just hit return again and se will throw away the buffer and terminate.
When you receive the prompt from the shell, the buffer has been thrown away; there is absolutely no way to recover it. If you wrote the contents of the buffer to a file, then this is of no concern; if you did not, it may mean disaster.
As a convenience feature to reduce the risk of losing data, se provides a “write then quit” command:
wq
This command will first write your file to disk, then exit from se. If any errors occur while writing the file, se will not quit but will display a message on the status line.

If you are not sure whether or not you have written your file, se provides a simple way of checking. Type

ok
and se will reply either ‘saved’ or ‘not saved’ on the status line. (This command is actually an se “option”.)

Reading files - the Enter command

Of course, most of the time you will not be entering text into the buffer for the first time. You need a way to fill the buffer with the contents of some file that already exists, so that you can modify it. This is the purpose of the “enter” command ‘e’; it enters the contents of a file into the buffer. To try out “enter”, you must first get back into the editor:
$ se
“Enter” is used like this:
e file
File’ is the name of a file to be read into the buffer.

Note that you are not restricted to editing files in the current directory; you may also edit files belonging to other users (provided they have given you permission). Files which are not in the current directory must be identified by their full “pathname”. If you are not familiar with the idea of a pathname, you should read the manual for your system, or consult a guru. For example, to edit a file named “document” belonging to user “tom”, you would enter the following command:

e /usr/tom/document

After the file's contents are copied into the buffer, se displays the number of lines it read (on the status line, as usual). In our example, the buffer would now contain:

The quick brown fox
    jumps over
   the lazy dog.
If anything at all is present in the buffer, the ‘e’ command destroys it before reading the named file.

As a matter of convenience, se remembers the file name specified on the last ‘e’ command, so you do not have to specify a file name on the ‘w’ command. The remembered name always appears on the status line, usually near the left-hand end. With these provisions, a common editing session looks like

$ se
e file
{editing}
w
q
The “file” command (‘f’) is available for changing the remembered file name. To change the name, just type:
f new-name   

You might also want to check that

$ se file
is exactly the same as
$ se
e file
That is, se performs an ‘e’ command for you if you give it a file name on the command line.

Errors - (editing rejected commands)

Occasionally, an error of some kind is encountered. Often, these are caused by misspelled file names. Another possible cause is that you have specified a command which does not exist. Whenever an error occurs, se displays a brief message on the status line. It is usually clear what caused the problem, but if not, you may need to consult this guide.

In most cases, when an error occurs, se leaves your command intact on the command line: at these times you are being given the opportunity to edit your command and try again. You should use the backspace key to edit your command and correct it. When you think you have got it right, move to the right-hand end of the command and hit return again.

We will see later on how to use other keys to add extra text into the middle of your command.

If you try to quit without saving your buffer, you will be given a message saying ‘Buffer hasn't been saved’, and the cursor will be left at the end of the command line with your “quit” command intact. Beware! If you press return a second time, se will exit and your work will be lost. To save your work, erase the ‘q’ command using the backspace key, and use the ‘w’ command.

If the file that you ask for in the ‘e’ command cannot be found, or if you have no permission to read it, se will display a message ‘File is not readable’ in the status line. In this situation, check the name of the file and directory and try again.

Viewing text

As mentioned above, you are likely to need to edit files much bigger than the screen can display all at once. Se provides several commands to allow the user to see different parts of a large file. Before we look at commands, however, some terminology is required.

The part of the buffer that is visible on the screen is called the “window”, for obvious reasons. The window can be moved up and down the file as required, or it can be moved left and right to look at very long lines. Se has one special line called the “current line”. The current line is the last line you have edited in any way, and se always marks this line with a little arrow ‘->’ in the left margin. (On some computers, the arrow will highlighted on the display.) In the margin, you will see the “line labels”. These are capital letters that can be used to identify a line.

At this point, some word processor users might be wondering what happened to pages and “page breaks”. Se is not a word processing program and as such does not constrain the user to the size of a page, either in height or width. Since se is often used to edit program source code, this is an important feature. Of course, se can be used to prepare text for a document formatter, but it is up to the formatter program to worry about page breaks.

The simplest way to move to a line is to name it, that is, type its label on the command line, and hit return. Be sure to type line labels in capitals! When you do this, watch the “current line” arrow jump up and down in the margin. This works fine for lines that are visible on the screen, but cannot be used to move the window.

If you simply press return without typing a command or a line label, se moves the current line down to the line below it. Again, the arrow moves in the margin. If the arrow reaches the bottom of the window, se is forced to move the window because the current line must always be visible. Watch carefully to see how it does this, and also note that the line labels remain “fixed” in the left margin (they label lines in the window, not lines in the buffer).

Another method of moving down the file is to use the “cursor down” key, control-K. Similarly, to move up, use the “cursor up” key, control-D. Once again, se will move the window when the current line reaches either the top or the bottom.

It is often quicker when moving large distances to move the window by more than a single line at a time. Se provides two commands to do this, ‘:’ and ‘p’. They both move the window by a complete screenful, the colon command moving it forwards (down) and the ‘p’ command moving it backwards (up). To move down by a screenful, type the command

:
and to move the window up by a screenful, type
p
If you look carefully you will see that se allows an overlap of one line to make it a little easier to read over the join. As before, it is possible to use single keystrokes to move up and down by a screenful. The “page down” key, control-S and the “page up” key, control-Q should do the same thing as ‘:’ and ‘p’, respectively.

However, to move larger distances than one screenful, especially in large files, you will find it more convenient to use a different method of identifying lines. Se can label lines either with capital letters, as we have seen, or with numbers. When it uses numbers, the first line in the file is numbered one, the second two, and so on. It makes no difference where the window is positioned and you can refer to a line by number whether you can see it or not.

So how do we tell se to use line numbers? Simply type:

oa
and you will see the capital letters disappear and numbers replace them. Also you should know that saying
oa
again will restore the previous way of working. Use whichever system is more appropriate to the job in hand; you can switch freely between the two.

So, we can now jump straight to any line in the buffer simply by typing its number on the command line and pressing return. If you type a line number that is too big or too small, se will display a message ‘Line number out of range’ on the status line. If you type a number which refers to a line that is off the screen, se will move the window so that the line is visible again.

There are also some special labels: Suppose we want to visit the last line in the buffer, but we don't know what its number is. Se provides an abbreviation to specify the last line in the buffer:

$
The dollar sign can be used just like a number. We will see later the usefulness of the “current line” symbol, ‘.’ (read “dot”). Another special label is ‘#’; it refers to the top line of the window.

If you are using se with alphabetic line labels, it is sometimes useful to know that you can type

.=
and se will display the number of the line. You can then refer to the line by number, even if numbers are not being displayed in the margin.

Finally, a brief mention of how to move the window left and right. If you type:

olm4
se will move the window to the right so that the fourth character on each line appears at the left margin. Typing:
olm1
restores normality; the first character on each line appears at the margin. (There is no keystroke to do this.)

Correcting Mistakes In Text

You may, by this point, have typed in many lines of text but we have not yet introduced any ways to correct typing mistakes — apart from the backspace key. Since it is too late to use backspace once you have pressed return, you probably have several lines that need corrections. So, this section will introduce the “substitute” command (in its simplest form) so that you can correct your text and the “delete” command to remove lines altogether.

First, you must locate your mistake and make it the current line. For example, you may have a mistake on line 5 of the buffer, so you would get there by typing:

5
as explained above. Let's say you have typed “left” instead of “right”. You need to tell se to find the word “left” and substitute the word “right”; the following command will do this:
s/left/right/
We will see later how to use more complex forms of this command to do more complex corrections.

After a little experimentation with ‘s’, you may discover that you can eliminate all the text on a line, but you cannot delete the line altogether. There is a different command, ‘d’, to do this.

Once you have found the line that you want to delete, type

d
and it will disappear. All the lines below it will be moved up to fill the gap. Later, we will see ways of deleting many lines with one command.

The Story So Far

This is a good place to look over what we have seen so far and mention a few useful hints.

The following commands have been described:


Append a OK ok Enter e Left Margin olm Write w Line Numbers oa Quit q Equal = Page Down : Page Up p Substitute s Delete d
In addition, we have described how to move to any line in the buffer by typing its number or by using the symbols ‘.’, ‘#’ and ‘$’.

You should now know enough about se to start it up, type in text or read it from a file, make corrections, move around the document, write text into a file, and quit. It is probably best to practice a little at this stage, but avoid really long documents just in case!

If you are worried that se is rather tedious to use, remember that we haven't described any of the more powerful commands and techniques yet. When we do, you will probably find the way of using se that suits you, and may even go on to customise it for yourself!

It is often useful to be reminded of se's commands or keystrokes while actually using it. This is quite easy; se provides a “help” command that displays brief descriptions of the facilities available. To start with, just type

h
and you will see the introductory screen. The information appears in the upper part of the screen, separated from your text by a horizontal line. On the status line, se will say ‘Enter o- to restore display’. If you type, as it says,
o-
the help message will vanish and your text will once again fill the screen.

As shown on the introductory screen, you can type ‘hdir’ to get a directory of help topics. Within each topic there is an introduction and another directory. If you examine the command directory, you will find that typing ‘ha’ will produce a help screen about the “append” command.

Multi-line commands

So far, we have only seen commands that affect a single line. However, most commands are capable of affecting more than one line at a time. It is this ability to operate on many lines with just one command that gives se its power. Imagine the work involved in correcting the spelling in a large American document, ready for publishing in England. Every time the word “color” is used, it must be changed into “colour”. In some editors, you would have to search the text manually and correct the spelling by re-typing each time the word is found. Se allows this type of substitution to be done fully automatically throughout a document. Not only does se speed up the process, it also eliminates the kind of error where one of the corrections is overlooked. This is especially important when editing program source code.

One way of specifying a set of lines for some operation is to use a “range”. A range of lines is a continuous sequence of lines with a known starting line and a known finishing line. (You will find out later how to perform operations on scattered groups of lines). A range is used as a prefix to a command and is uniquely specified by its starting and ending lines. You describe a range by typing the number of the first line in the range, followed by a comma and the last line in the range. For example

1,7s/left/right/
makes the substitute command apply to all of the lines one to seven, inclusive.

Although the above example uses simple line numbers, it is quite usual to employ the special symbols mentioned above. To go back to the problem of changing American spelling to English, we might say

1,$s/color/colour/
which would affect all the lines in the buffer. (Note that this only makes one substitution per line — see the section on substitute.)

A combination of ‘.’ and ‘,’ can be used in many ways. Unlike most commands, the ‘w’ command refers to the whole buffer by default and needs to be given line numbers in order to refer to only a part of the buffer. For example,

1,.w file          
copies from the start of the buffer up to the current line into ‘file’, and
.,$w file
copies from the current line to the end of the buffer into ‘file’. If you want just the current line written into the file, try:
.w file

Deleting Lines

Deletion was mentioned earlier as a way of removing unwanted lines from the buffer. Usually, it is handy to delete several lines in one go. This is where line ranges become really useful. For instance, to delete the first 20 lines in a file, type:
1,20d
The ‘d’ command expects line numbers that work in the same way as those specified above, deleting one line or any range of lines.
d
deletes only the current line. It is the same as ‘.d’ or ‘.,.d’.

After a deletion, the current line pointer is left pointing to the first line after the group of deleted lines, unless the last line in the buffer was deleted. In this case, the current line is the last line before the group of deleted lines.

More Complicated Line Numbers

Se has several ways to specify lines other than just numbers and symbols like ‘$’. .’, for instance, is not particularly useful when used alone. It becomes much more important when used in “line-number expressions”. A line-number expression is used to make se do arithmetic with line numbers — usually addition and subtraction. Try this experiment:
.-3
.-3’ means “find the line that is three lines before the current line”.
.+1        
.+1’ means “find the line that is one line after the current line”.
.-2,.-1 w file     
This rather complex example means “save the lines from two lines before to one line before the current line”. It would in fact be easier to move up by two lines, either by using the cursor keys or typing ‘.-2’, and then issue the command:
.,.+1w file

You can also use ‘$’ in line-number expressions:

$-1
This means “find the line that is one line before the last line in the buffer, i.e., the next to the last line”.

Some abbreviations are available to help reduce the amount of typing you have to do. Typing a newline by itself is equivalent to typing ‘.+1’ and typing a caret, ‘^’, or a single minus sign, ‘-’, followed by a newline is equivalent to typing ‘.-1’.

It might be worthwhile to note here that almost all commands expect line numbers of one form or another. If none are supplied, se uses default values. Thus,

w file
is equivalent to
1,$w file
and
a
is equivalent to
.a
(which means, append text after the current line.)

Text Patterns

Frequently it is desirable to be able to find a particular “pattern” in a piece of text. For example, suppose that after proofreading a report you have typed in using se you find a spelling error. There must be an easy way to find the misspelled word in the file so it can be corrected. One way to do this would be to count all the lines up to the line containing the error, so that you can give the line number of the offending line to se. Obviously, this way is not very fast or efficient. Se allows you to “search” for patterns of text (like words) by enclosing the pattern in slashes:
/jumps/
Se looks for the pattern you specified, and moves to the first line which contains the pattern. Note that if we had typed
/jumped/
se would display a message on the status line ‘No line contains that pattern’; this would inform us that it could not find the pattern we wanted.

Se searches forward from the current line when it attempts to find the pattern you specified. If se reaches the last line without seeing the pattern, it “wraps around” to the first line in the file and continues searching until it either finds the pattern or gets back to the line where it started (line ‘.’). This procedure ensures that you get the “next” occurrence of the pattern you were looking for, and that you don't miss any occurrences because of your current position in the file.

Suppose, however, that you do not wish to find the “next” occurrence of a word, but the previous one instead. Very few text editors provide this capability; however, se makes it simple. Just surround the pattern with question-marks:

?quick?

The backward search (or backscan, as it is sometimes called) wraps around the file in a manner similar to the forward search (or scan). The search begins at the line before the current line, proceeds until the first line of the file is seen, then begins at the last line of the file and searches upwards until the current line is encountered. Once again, this is to ensure that you do not miss any occurrences of a pattern due to your current position in the file.

In pattern searches, and in other commands which we will get to later, se allows you to leave off the trailing delimiter. I.e., instead of typing

/jumps/
you can type
/jumps
to search forward for the first occurrence of the pattern ‘jumps’. Similarly, to search backward, you may type
?quick
instead of
?quick?
This feature can save considerable time and frustration when you are doing some involved editing, and accidentally leave off the trailing delimiter (‘/’ or ‘?’). The rest of this guide will continue to use examples with the trailing delimiter, but you do not have to in your actual editing.

Se also provides more powerful pattern matching services than simply looking for a given string of characters.

This section may seem fairly complicated at first, and indeed you do not really need to understand it completely for effective use of the editor. However, the results you might get from some patterns would be mystifying if you were not provided with some explanation, so look this over once and move on.

The pattern that may appear within slashes (or question-marks) is called a “regular expression”. It contains characters to look for and special characters used to perform other operations. The following characters

^  .  $  [  *  \  \(
have special meaning to se:

The last important thing you need to know about patterns is the use of the “default” pattern. Se remembers the last pattern used in any command, to save you the trouble of retyping it. To access the remembered pattern, simply use an “empty” string. For example, the following sequence of commands could be used to step through a file, looking for each occurrence of the string ‘ICS’:

/ICS/
//
//
(and so on)

One last comment before leaving pattern searching. The constructs

/pattern/
?pattern?
are not separate commands; they are components of line number expressions. Thus, to find the line after the next line containing ‘tape’, you could say
/tape/+1
Or, to use a range of lines from one before to one after a line with a given pattern, you could use
/pattern/-1,/pattern/+1

Making Substitutions - the Substitute command

This is one of the most used editor commands. As mentioned earlier, the “substitute” command ‘s’ is used to make small changes within lines, without retyping them completely. It is used like this:
starting-line,ending-line s [/pattern/new-stuff[/[g]]]
For instance, suppose our buffer looks like this:
The quick brown fox
    jumps over
   the lazy dog.
To change ‘jumps’ to ‘jumped’,
2s/jumps/jumped/

If the last string specified in the substitute command is empty, then the text matching the pattern is deleted:

s/jumped//
     over
s/^ */    jumps /
    jumps over
Recalling that a missing pattern means “use the last pattern specified”, try to explain what the following commands do:
s///
jumps over
s//    /
    jumps over
(Note that, like many other commands, the substitute command assumes you want to work on the current line if you do not specify any line numbers.)

What if you want to change ‘over’ into ‘over and over’? You might use

s/over/over and over/
    jumps over and over
to accomplish this. There is a shorthand notation for this kind of substitution that was alluded to briefly in the last section. (Recall the discussion of “tagged” patterns.) By default, the part of a line that was matched by the whole pattern is remembered. This string can then be included in the replacement string by typing an ampersand (‘&’) in the desired position. So, instead of the command in the last example,
s/over/& and &/
could have been used to get the same result. If a portion of the pattern had been tagged, the text matched by the tagged part in the replacement could be reused by typing ‘\1’:
s/jump\(.*\)/vault\1/
    vaults over and over
It is possible to tag up to nine parts of a pattern using ‘\(’ and ‘\)’. The text matched by each tagged part may then be used in a replacement string by typing
\n
where n corresponds to the nth part in the pattern. What does the following command do?
s/\([^ ]*\) \(.*\)/\2 \1/

Some more words on substitute: the slashes are known as “delimiters” and may be replaced by any other character except a newline, as long as the same character is used consistently throughout the command. Thus,

s#vaults#vaulted#
    vaulted over and over
is legal. Also, note that substitute changes only the first occurrence of the pattern that it finds; if you wish to change all occurrences on a line, you may append a ‘g’ (for “global”) to the command, like this:
s/ /*/g
****vaulted*over*and*over
In the replacement part of a substitute command, the character ‘&’, as the only character in the pattern, means “the replacement part of the previous substitute command”. (This allows an empty replacement pattern as well.) Thus, to step through the buffer, and change selected occurrences of one pattern into another, you might do the following:
/pat1/
Line containing pat1.
s/pat1/stuff1/
Line containing stuff1.
//
Another line with pat1.
//
Yet another line with pat1.
s//&/
Yet another line with stuff1.

Line Changes, Insertions, and Concatenations

Two “abbreviation” commands are available to shorten common operations applying to changes of entire lines. These are the “change” command ‘c’ and the “insert” command ‘i’.

The change command is a combination of delete and append. Its format is

starting-line,ending-line c
This command deletes the given range of lines, and then goes into append mode to obtain text to replace them. Append mode works exactly the same way as it does for the ‘a’ command; input is terminated by a full stop standing alone on a line. Examine the following editing session to see how change might be used:
1,$c
Se is an interactive program used for
the creation and modification of "text.
.
c
the creation and modification of "text."
"Text" may be any collection of character
data.
.
As you can see, the current line is set to the last line entered in append mode.

The other abbreviation command is ‘i’. ‘I’ is very closely related to ‘a’; in fact, the following two commands are equivalent:

4i
is the same as
3a
In short, ‘i’ inserts text before the specified line, whereas ‘a’ inserts text after the specified line.

The join command ‘j’ can be used to put two or more lines together into a single line. It works like this:

starting-line,ending-line j[/string[/]]
The defaults for starting-line and ending-line are ‘^’ and ‘.’ respectively, that is, “join the line before the current line to the current line”. You may specify in ‘string’ what is to replace the newline(s) which currently separate the lines which are to be joined. If you do not specify any string, se will replace the newline with a single blank. An extended example should make this clear:
The quick brown fox
jumps over                   
the lazy dog.
1,2j
The quick brown fox jumps over
the lazy dog.
1,2j/ the back of /
The quick brown fox jumps over the back of the lazy dog.

Overlay Mode - full-screen editing

If editing with se looks rather complicated so far, you may find it easier to use “overlay mode”. In fact, some screen editors have no command line at all and can only be used in this mode.

Some of se's control keys have already been mentioned; cursor up and down, page up and down. In overlay mode, we make use of all the control keys.

To switch se into overlay mode, type:

v
The cursor jumps from the command line into the window and lands at the far right-hand end of the current line. Pressing return will make it jump back again.

So, now that we can place the cursor in the window, how do we edit the text? This is where we use the control keys to move the cursor around, delete characters and insert spaces for new characters.

Perhaps we want to remove the last couple of characters from the current line, using overlay mode. First, switch se into overlay mode with the ‘v’ command. Then, press backspace twice and the cursor moves two places to the left. Press return and the line is “chopped off” at the cursor position — just what we wanted. Whenever you press return, se first chops off the line, then switches back into command mode.

When in overlay mode, the cursor up and down keys, control-D and control-K work as usual; so do page up and down, control-Q and control-S. To move the cursor to the start of the line, type control-W, and to move to the end, type control-O.

If you type ordinary characters, they will overwrite any characters already there; this is known as “overtype mode”. To make characters insert themselves into the text, moving the rest of the line along to make room, you must put se into “insert mode”. To do this, type control-A; the word ‘INSERT’ will appear on the status line. Pressing control-A again will turn insert mode off. If you simply want a single blank space inserted, use control-C.

To delete characters you can use control-R which will erase the character under the cursor and move the rest of the line left to fill the gap. Control-U is similar but erases the character to the left of the cursor.

Finally, when you have finished using overlay mode, you may find it useful to type control-V. This switches back to command mode in the same way as return, but does not chop the line off first. If, however, you have botched the edits and want to restore the current line to its original state, control-F will do this.

In fact, nearly all the control characters do something in overlay mode and either the “help” command or the reference manual give the full list.

Moving Text

Throughout this guide, we have concentrated on what may be called “in-place” editing. The other type of editing commonly used is often called “cut-and-paste” editing. The move command ‘m’ is provided to facilitate this kind of editing, and works like this:
starting-line,ending-line m after-this-line
If you wanted to move the last fifty lines of a file to a point after the third line, the command would be
$-49,$m3
Any of the line numbers may, of course, be full expressions with search strings, arithmetic, etc.

The current line is set to the last line moved.

Global Commands

The “global” command ‘g’ is used to perform an editing command on all lines in the buffer that match a certain pattern. If you wanted to correct some common spelling error, you would use
g/old-stuff/s//new-stuff/g
which makes the change in all appropriate lines. (Technical note: there is a difference between ‘1,$s/old-stuff/new-stuff/g’ and ‘g/old-stuff/s//new-stuff/g’. It has to do with the method of pattern-matching, and hence the speed.) Another example; deleting all lines that begin with an asterisk could be done this way:
g/^\*/d

G’ has a companion command ‘x’ (for “eXclude”) that performs an operation on all lines in the buffer that do not match a given pattern. For example, to delete all lines that do not begin with an asterisk, use

x/^\*/d

G’ and ‘x’ are very powerful commands that are essential for advanced usage, but are usually not necessary for beginners. Concentrate on other aspects of se before you move on to tackle global commands.

Marking Lines

During some types of editing, especially when moving blocks of text, it is often necessary to refer to a line in the buffer that is far away from the current line. For instance, say you want to move a subroutine near the beginning of a file to somewhere near the end, but you aren't sure that you can specify patterns to properly locate the subroutine. One way to solve this problem is to find the first line of the subroutine, then use the command ‘.=’:
/subroutine/
   subroutine think
.=
47
and write down (or remember) line 47. Then find the end of the subroutine and do the same thing:
/end/
   end
.=
71
Now you move to where you want to place the subroutine and enter the command
47,71m.
which does exactly what you want.

The problem here is that absolute line numbers are easily forgotten, easily mistyped, and difficult to find in the first place. It is much easier to have se remember a short “name” along with each line, and allow you to reference a line by its name. In practice, it seems convenient to restrict names to a single character, such as ‘b’ or ‘e’ (for “beginning” or “end”). It is not necessary for a given name to be uniquely associated with one line; many lines may bear the same name. In fact, at the beginning of the editing session, all lines are marked with the same name: a single space.

To return to our example, using the ‘k’ command, we can mark the beginning and ending lines of the subroutine quite easily:

/subroutine/
   subroutine think
kb
/end/
   end
ke
We have now marked the first line in the subroutine with ‘b’ and the second line with ‘e’.

To refer to names, we need more line number expression elements: ‘>’ and ‘<’. Both work in line number expressions just like ‘$’ or ‘/pattern/’. The symbol ‘>’ followed by a single character mark name means “the line number of the first line with this name when you search forward”. The symbol ‘<’ followed by a single character mark name means “the line number of the first line with this name when you search backward”. (Just remember that ‘<’ points backward and ‘>’ points forward.)

Now in our example, once we locate the new destination of the subroutine, we can use ‘<b’ and ‘<e’ to refer to lines 47 and 71, respectively (remember, we marked them). The “move” command would then be

<b,<em.

Several other features pertaining to mark names are important. First, the ‘k’ command does not change the current line ‘.’. You can say

$kx
(which marks the last line with ‘x’) and ‘.’ will not be changed. If you want to mark a range of lines, the ‘k’ command accepts two line numbers. For instance,
5,10ka
marks lines 5 through 10 with ‘a’ (i.e., gives each of lines 5 through 10 the markname ‘a’).

The ‘n’, ‘~’ and apostrophe commands also deal with marks. The ‘n’ command by itself erases the mark of the current line. If the ‘n’ command is followed by a mark name, like

4nq
it marks the line with that mark name, and erases the marks on any other lines with that name. In this case, line 4 is marked with ‘q’ and it is guaranteed that no other line in the file is marked with ‘q’.

The ‘~’ and apostrophe commands are both global commands that deal with mark names. The apostrophe command works very much like the ‘g’ command: the apostrophe is followed by a mark name and another command; the command is performed on every line marked with that name. For instance,

'as/fox/rabbit/
changes the first ‘fox’ to ‘rabbit’ on every line that is named ‘a’. The ‘~’ command works in the same manner, except that it performs the command on those lines that are not marked with the specified name. For example, to delete all lines not named ‘k’, you could type
~kd

Undoing Things - the Undo Command

Unfortunately, Murphy's Law guarantees that if you make a mistake, it will happen at the worst possible time and cause the greatest possible amount of damage. Se attempts to prevent mistakes by doing such things as working with a copy of your file (rather than the file itself) and checking commands for their plausibility. However, if you type
d
when you really meant to type
a
se must take its input at face value and do what you say. It is at this point that the “undo” command ‘u’ becomes useful. “Undo” allows you to “undelete” the last group of lines that was deleted from the buffer. In the last example, some inconvenience could be avoided by typing
^ud
which restores the deleted line. (By default “undo” replaces the specified line by the last group of lines deleted. Specifying the ‘d’, as in ‘ud’, causes the group to be inserted after the specified line instead.)

The problem that arises with “undo” is the answer to the question: “What was the last group of lines deleted?” This answer is very dependent on the implementation of se and in some cases is subject to change. After many commands, the last group of lines deleted is well-defined, but unspecified. It is not a good idea to use the “undo” command after anything other than ‘c’, ‘d’, or ‘s’. After a ‘c’ or ‘d’ command,

ud
places the last group of deleted lines .ul after the current line. After an ‘s’ command (which by the way, deletes the old line, replacing it with the changed line),
u
deletes the current line and replaces it with the last line deleted — it exactly undoes the effects of the ‘s’ command. But beware! If the ‘s’ command covered a range of lines, ‘u’ can only restore the last of the lines in which a substitution was made; the others are gone forever.

You should be warned that while “undo” works nicely for repairing a single ‘c’, ‘d’, or ‘s’ command, it cannot repair the damage done by one of these commands under the control of a global prefix (‘g’, ‘x’, ‘~’ and apostrophe). Since the global prefixes cause their command to be performed many times, only the very last command performed by a global prefix can be repaired.

More Line Number Syntax

So far, the commands that you have seen can be given either no line numbers elements (the command tries to make an intelligent assumption about the line(s) on which to perform an operation), one line number element (the command acts only on that line), or two line numbers separated by a comma (the command acts on the given range of lines). There is one more way to specify line number elements, and that is to separate them by a semicolon. When line number elements are separated by semicolons, each line number element encountered sets the “current line” marker before the next line number element is evaluated. This is especially useful when using patterns as line number elements; some examples will illustrate what we mean.

Suppose that you wanted to change all the lines which lie between two lines, each containing the string ‘fred’. An initial effort might yield the following command line:

/fred/,/fred/s/sam/bill         
This, however, will only change the first line which contains ‘fred’ after the current line. This is because both patterns will start their search after the current line where the command was executed, instead of the second one starting where the first pattern was found. To correct this, we would issue the following:
/fred/;/fred/s/sam/bill
When the first occurrence of ‘fred’ is found, the “current line” is set to that line, and the second occurrence of ‘fred’ will be found starting at this new line. This will change the lines between two succeeding occurrences of ‘fred’ from the current line.

As a final example, suppose that we wanted to change the lines between the second and third occurrence of ‘fred’ after the current line; to do this, we would do:

/fred/;//;//s/sam/bill
The first pattern search would find ‘fred’, the next two null strings will cause the previous pattern (‘fred’) to be searched for again, each time resetting the “current line” marker.

For both comma-separated and semicolon-separated line number elements, you may specify more than two such elements, as the above example shows; only the last two such elements will be used as the range for the given command. In general, using more than two line number elements separated by commas is not too useful, because the “current line” is not modified for any of the line number expression evaluations. Also, using integer line numbers means that multiple expressions (more than two) are not useful, since the equivalent behavior can be obtained by specifying only the last two line numbers.

Escaping to the Shell

It is often useful to be able to temporarily stop editing and return to the operating system. Sometimes you want to execute just a single command, sometimes several. Se has a command, ‘!’ that does exactly that.

If you type the following command:

!
se will start up a “subshell”. You can type commands just as you would do normally, but all the time se is ready to restart exactly where you left off. To tell the subshell that you want to get back into se, type the command:
exit
Se will the redraw the editing screen and carry on.

If you just want to run a single command, put it on the command line after the ‘!’. For instance,

!ls
would give you a directory listing. After command is finished, se displays ‘type return to continue:’ to indicate that the shell escape has completed and to allow the user time to read the output.

If the first character of the shell command is a ‘!’, then the ‘!’ is replaced with the text of the previous shell command. In other words, typing

!!
will repeat the last shell command. Try it, and see how the remembered shell command is put back on the se command line for re-editing. Pressing return again will cause the command to be executed.

An unescaped ‘%’ in the shell command will be replaced with the current saved file name. If the shell command is expanded in this way, se will echo it first, and then execute it. In the following example, the shell escape is used with a ‘%’ in order to examine the current file:


!ls -l %

ls -l file

-rw-r--r--  1 tom     19463 Jun 17 16:25 file

type return to continue:
Remember when using ‘%’ to write the buffer out first — you should notice a warning on the se status line if you forget.

Summary

This concludes our tour through the world of text editing. You should now know enough about se to use it for most editing tasks. If you want to know more, refer to one of the documents mentioned below.

The Se Applications Note describes some typical cases of using se to edit files. Commonly used commands are explained together with handy hints to get more out of se. Configuring se is also mentioned.

The Se Technical Reference lists all available se commands, options, control characters, line number elements and pattern-matching metacharacters. It the definitive reference for the more technically minded reader.

The Se Developer's Guide describes the internals of se from the point of view of a programmer. It details how to port se onto new hardware, how to add commands and how to alter se's default configuration.

For those interested in copying se, the Licence gives all the details.

All the above documents are available either on a computer or in printed form. The printed form is useful if you wish to run se on the computer and read the manual alongside; the computerised version can, however, be searched more easily and is useful as a reference. If you need printed copies, see your local guru.