Use this nostalgic text editor on FreeDOS

Edlin is a joy to use when I want to edit text the "old school" way.
33 readers like this.
Old UNIX computer

Opensource.com

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 replace Edlin eventually, 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, portable editor. You can even compile Edlin on Linux. As Gregory described Edlin in the free ebook 23 Years of FreeDOSThe 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 a 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 lowercase 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.

C:\EDLIN> edlin hello.c
edlin 2.19, 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.

hello.c: 0 lines read
*

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.

*i
 : #include <stdio.h>
 : 
 : int
 : main()
 : {
 :   puts("Hello world");
 : }
 : .
*

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:

*l
1: #include <stdio.h>
2: 
3: int
4: main()
5: {
6:   puts("Hello world");
7:*}
*

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.

*i
 :   return 0;
 : .
*l
1: #include <stdio.h>
2: 
3: int
4: main()
5: {
6:   puts("Hello world");
7:   return 0;
8:*}
*

But what if you need to edit a single line in the file? At the * prompt,simply 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.

*4
4:*main()
4: main(void)
*l
1: #include <stdio.h>
2: 
3: int
4:*main(void)
5: {
6:   puts("Hello world");
7:   return 0;
8: }
*

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.

*w
hello.c: 8 lines written
*q
C:\EDLIN>

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).

? Show help
num Edit a single line
a Append a line below the mark
[num]i Insert new lines before the mark
[num][,num]l List the file (starting 11 lines above the mark)
[num][,num]p Page (same as List, but starting at the mark)
[num],[num],num,[num]c Copy lines
[num],[num],numm Move lines
[num][,num][?]stext Search for text
[num][,num][?]rtext,text Replace text
[num][,num]d Delete lines
[num]tfilename Transfer (insert the contents of a new file at the mark)
[num]w[filename] Write the file to disk
q Quit Edlin
e[filename] End (write and quit)

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

\a alert
\b backspace
\e escape
\f formfeed
\t horizontal tab
\v vertical tab
\" double quote
\' single quote
\. period
\\ backslash
\xXX hexadecimal number
\dNNN decimal number
\OOO octal number
\^C control character
What to read next

How FreeDOS boots

An overview of how your computer boots up and starts a simple operating system like FreeDOS.

Why FreeDOS has 16 colors

Why does text only come in this limited palette, and why does FreeDOS use those colors and shades, instead of some other colors? The answer, like many things in technology, is…

(Correspondent)
June 17, 2021
photo of Jim Hall
Jim Hall is an open source software advocate and developer, best known for usability testing in GNOME and as the founder + project coordinator of FreeDOS.

Comments are closed.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.