How to edit text with Edlin

In the very early days of DOS, the standard editor was a no-frills line editor called Edlin. Tim Paterson wrote the original Edlin for the first version of DOS, then called 86-DOS and later branded PC-DOS and MS-DOS. Paterson has commented that he meant to eventually replace Edlin, but it wasn't until ten years later that MS-DOS 5 (1991) replaced Edlin with Edit, a full-screen editor.

You may know that FreeDOS is an open source DOS-compatible operating system that you can use to play classic DOS games, run legacy business software, or develop embedded systems. FreeDOS has very good compatibility with MS-DOS, and the "Base" package group includes those utilities and programs that replicate the behavior of MS-DOS. One of those classic programs is an open source implementation of the venerable Edlin editor; Edlin is distributed under the GNU General Public License version 2.

Written by Gregory Pietsch, Edlin is a well designed editor. As Gregory described Edlin in the free ebook 23 Years of FreeDOS, The top tier parses the input and calls the middle tier, a library called edlib, which calls the string and array-handling code to do the dirty work. But aside from its technical merits, I find Edlin is a joy to use when I want to edit text the "old school" way

FreeDOS 1.3 RC4 includes Edlin 2.18. That's actually one revision out of date, but you can download Edlin 2.19 from the FreeDOS files archive on Ibiblio. You'll find two files there; edlin-2.19.zip contains the source code, and edlin-219exe.zip is just the DOS executable. Download the edlin-219exe.zip file, and extract it to your FreeDOS system. I've unzipped my copy in C:\EDLIN.

Edlin takes a little practice to "get into" it, so let's edit new file to show a few common actions in Edlin:

A walkthrough

Start editing a file by typing EDLIN and then the name of the file to edit. For example, to edit a C programming source file called HELLO.C, you might type:

C:\EDLIN> edlin hello.c

(I've typed the FreeDOS commands in all uppercase here. FreeDOS is actually case insensitive, so you can type commands and files in uppercase or lowercase. Typing edlin or EDLIN or Edlin would each run the Edlin editor. Similarly, you can identify the source file as hello.c or HELLO.C or Hello.C.

edlin
Editing a new file in Edlin

Once inside Edlin, you'll be greeted by a friendly * prompt. The interface is pretty minimal; no shiny "menu" or mouse support here. Just type a command at the * prompt to start editing, revise lines, search and replace, save your work, or exit the editor.

Since this is a new file, we'll need to add new lines. We'll do this with the insert command, by typing i at the * prompt. The Edlin prompt changes to : where you'll enter your new text. When you are done adding new text, type a period (.) on a line by itself.

edlin
Enter . on a line by itself to stop entering new text

To view the text you've entered so far, use the list command by entering l at the * prompt. Edlin will display lines one screenful at a time, assuming 25 rows on the display. But for this short "Hello world" program, the source code fits on one screen:

edlin
Use the l command to list the file

Did you notice the * on line 7, the last line in the file? That's a special mark indicating your place in the file. If you inserted new text in the file, Edlin would add it at this location.

Let's update the C source file to return a code to the operating system. To do that, we'll need to add a line above line 7. Since that's where Edlin has the mark, we can use i to insert next text before this line. Don't forget to enter . on a line by itself to stop entering the new text.

By listing the file contents afterwards, you can see that we inserted the new text in the correct place, before the closing "curly brace" in the program.

edlin
Use the i command to insert text above the mark

But what if you need to edit a single line in the file? At the * prompt, imply type the line number that you want to edit. Edlin works one line at a time, so you'll need to re-enter the full line. In this case, let's update the main() function definition to use a slightly different programming syntax. That's on line 4, so type 4 at the prompt, and re-type the line in full.

Listing the file contents afterwards shows the updated line 4.

edlin
Enter a line number to re-enter the line

When you've made all the changes you need to make, don't forget to save the updated file. Enter w at the prompt to write the file back to disk, then use q to quit Edlin and return to DOS.

edlin
Write the file with w, and use q to quit

Quick reference guide

That walkthrough shows the basics of using Edlin to edit files. But Edlin does more than just "insert, edit, and save." Here's a handy cheat sheet showing all the Edlin functions, where text indicates a text string, filename is the path and name of a file, and num is a number (use . for the current line number, $ for the last line number).

numEdit a single line
aAppend a line below the mark
[num]iInsert new lines before the mark
[num][,num]lList the file (starting 11 lines above the mark)
[num][,num]pPage (same as List, but starting at the mark)
[num],[num],num,[num]cCopy lines
[num],[num],nummMove lines
[num][,num][?]stextSearch for text
[num][,num][?]rtext,textReplace text
[num][,num]dDelete lines
[num]tfilenameTransfer (insert the contents of a new file at the mark)
[num]w[filename]Write the file to disk
qQuit Edlin
e[filename]End (write and quit)

Programmers will be interested to know they can enter special characters in Edlin, using these special codes:

\aalert
\bbackspace
\eescape
\fformfeed
\thorizontal tab
\vvertical tab
\"double quote
\'single quote
\.period
\\backslash
\xXXhexadecimal number
\dNNNdecimal number
\OOOoctal number
\^Ccontrol character