motherboard A look back: the Edlin editor

Explore classic editing with Edlin, the original line editor from the DOS era.

Edlin was the original line editor for the MS-DOS operating system. Like Unix ed and other line editors, Edlin works on one line at a time. It's a different way to edit files, from a time when computers measured memory in kilobytes.

Gregory Pietsch created the open source implementation of Edlin for the FreeDOS Project. FreeDOS Edlin is a classic "retro" line editor, but with a few modern twists such as relative line addressing. With Gregory's Edlin, you can experience what it was like to edit files "by hand" like the early 1980s.

We asked Gregory about the history of Edlin, and how you can use Edlin to work on files:

Let's start with an introduction

My name is Gregory Kenneth Pietsch, and I have been interested in computers since I was young. I have a BS in Computer Science from Glassboro State College in Glassboro, New Jersey (before it changed its name to Rowan University).

I had been using MS-DOS since the 1980s. By the late 1990s, I had discovered the FreeDOS project and noticed that they didn't have a free version of Edlin, the line editor that came with versions of MS-DOS from 1.00 to 5.00. I had the time to do it, so I chained myself to a desk for a week and wrote version 1.0, which I probably should have called 0.0 in retrospect.

I have been maintaining my own code for more than twenty years. Now, FreeDOS Edlin is very stable. As FreeDOS Edlin is open source and none of the code comes from the original MS-DOS Edlin (which was written in Assembler), if anyone thinks it stinks or could improve it, do not hesitate to write to me!

I have also written many other things that I have put under the GPL [GNU General Public License] or in the public domain for FreeDOS. This includes but is not limited to a version of libm (the math library), libmpi (a multi-precision integer library), cat and wc (for the Unix section), and a few other things over the years.

What is a line editor?

Before graphical user interfaces existed, there had to be an editor that would work in a purely textual environment, and possibly a terminal with a paper output. Such editors were called line editors.

The Edlin line editor allows the user to edit text files. The original MS-DOS version of Edlin was written by Tim Paterson back around 1980 or so for MS-DOS 1.00, and he wrote it in 16-bit MS-DOS Assembler. I don't think he was thinking of the future when he wrote it. When I wrote my version, I wrote it in C to make it a lot more portable and adaptable to different environments.

I believe CP/M had an editor called e, and various versions of it are in the old C User's Group library dating to the early 1980s, if not earlier. Somebody might resurrect it for the editors in FreeDOS. MS-DOS's original Edlin was "crufted" together in six weeks by Tim Paterson at Seattle Computer Products, who is said to have regretted it ever since. He expected it to have a six-month shelf life, but it remained in MS-DOS until version 5.00 ten years later.

What can Edlin do?

Before I wrote my version of Edlin, I did some online research as to the features the original one had. Surprisingly, there were a few versions of Edlin out there that had "featurectomies" done to them for some reason. I started with MS-DOS's manual for a list of the subfeatures that I had to implement, and the first version had all of them implemented.

The user of FreeDOS Edlin can append text to a file, insert text into a file, insert a file into another file, delete lines of text, search for a specific string, and even do find-and-replacement of strings. You can copy lines of text or move them around. There's even a help screen and good documentation!

I also added relative line addressing, so one can use a period for the current line, a dollar sign for the last line, or force the interpreter to do a little math (for example, 1+1i would insert text before line 2). I later added the octothorpe (#) for one line after the last line because I found that wrinkle in some very old documentation.

Why did you create Edlin? How do you create an editor like Edlin?

I created Edlin because I saw the list of programs that FreeDOS had in 2003 and Edlin was not one of them, so I filled that need. I created Edlin as a three-tier system: a parser would parse the user's commands and send that to a second level that implemented them using a third level of string and array functions. One could use the back end of Edlin in a full-screen editor, just changing the interface so that the full-screen editor works, but some full-screen editors use a different scheme such as a buffer-gap scheme to do the dirty work.

How does one create a line editor? It starts with a vision, a blinding flash of enlightenment. Then the code forms in your head, which you quickly write down.

How do you use Edlin?

Edlin mostly works on plain text files. Source code, HTML, batch files, anything plain text. It allocates its buffers dynamically, so the only limit is how much memory is available in the system.

Edlin is useful for small editing tasks, but I wouldn't use it for "War and Peace" if I were Tolstoy. The system I wrote it on is a Cygwin system but I made it as portable as possible so that it would work on FreeDOS, Linux, or anything in between. I normally use a full-screen editor called joe, but I can do editing using my own software!

The biggest thought I had with what to do with the code would be to write a software versioning system and have the part that stores the differences between the files write that using Edlin's commands, then call Edlin to do the modifications. I haven't written anything yet, though. Edlin can also be used in batch processing!


Thanks to Gregory for this look into classic editing with Edlin. If you want to try Edlin for yourself, you can download it from FreeDOS Edlin on SourceForge. You can compile Edlin 2.24 (released in May 2024) on a variety of systems including DOS, Windows command line, and Linux.

If you want to see what it's like to edit files using Edlin, here's a sample Edlin session that shows how to relocate lines with the m command. To use the m command, you provide the starting and ending lines to move, then the line number where the text should go, then the m command will move those lines before the destination line. For example, 2,3,1m will move lines 2 and 3 to before line 1. And 1,2,#m will move lines 1 and 2 to the end of the line (the # means the line after the last line of the file).

C:\>edlin about.txt
about.txt: New file.
*a
 : Edlin is the classic line editor from the MS-DOS era. You can use Edlin
 : to work on all kinds of text files.
 : 
 : Let's enter a few lines that are out of order so we can move them
 : around with the 'm' command:
 : 
 : three
 : two
 : one
 : .
*?
edlin 2.24, copyright (c) 2003 Gregory Pietsch
This program comes with ABSOLUTELY NO WARRANTY.
It is free software, and you are welcome to redistribute it
under the terms of the GNU General Public License -- either
version 2 of the license, or, at your option, any later
version.

edlin has the following subcommands:

#                 edit a single line    [#],[#],#m        move
a                 append                [#][,#]p          page
[#],[#],#,[#]c    copy                  q                 quit
[#][,#]d          delete                [#][,#][?]r$,$    replace
e<>               end (write & quit)    [#][,#][?]s$      search
[#]i              insert                [#]t<>            transfer
[#][,#]l          list                  [#]w<>            write

where $ above is a string, <> is a filename,
# is a number (which may be .=current line, $=last line,
or either number + or - another number).

*l
1: Edlin is the classic line editor from the MS-DOS era. You can use Edlin
2: to work on all kinds of text files.
3: 
4: Let's enter a few lines that are out of order so we can move them
5: around with the 'm' command:
6: 
7: three
8: two
9:*one
*9,9,7m
*7,9l
7: one
8: three
9:*two
*8,8,#m
*l
1: Edlin is the classic line editor from the MS-DOS era. You can use Edlin
2: to work on all kinds of text files.
3: 
4: Let's enter a few lines that are out of order so we can move them
5: around with the 'm' command:
6: 
7: one
8: two
9:*three
*w
about.txt: 9 lines written
*q
Really quit (Y/n)? y
C:\>