We ❤️ Open Source
A community education resource
Edlin on FreeDOS: When a simple line editor is all you need
DOScember spotlight: How to write C programs using nothing but a command prompt and a line editor.
Read the entire DOScember series and boot into vintage computing.
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) finally included 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 software, or create your own programs. The “Base” package group includes those utilities and programs that replicate the behavior of MS-DOS, including an open source implementation of the venerable Edlin editor.
FreeDOS includes lots of other, more powerful editors that you can use to write programs, including Bloček (which supports Unicode characters), Fed (a folding editor), MinEd (supports both Unicode and CJK), Pico (the Pine Composer), Freemacs (similar to GNU Emacs) and several versions of the Vi editor. But I will always love FreeDOS Edlin for its nostalgia and simplicity. Written by Gregory Pietsch, FreeDOS Edlin is a well-designed, portable version of the classic editor.
Edlin takes a little practice to “get into” it, so let’s demonstrate by editing a new file and using a few common actions in Edlin.
Read more: 26 commands to get started with FreeDOS
Getting started: Writing a simple C program with Edlin
Let’s create a sample program that prints a list of numbers from 1 to 10. Start editing a new file by typing EDLIN and then the name of the file to edit, TEN.C. Like any DOS, FreeDOS is actually case insensitive, so you can type commands and filenames in uppercase or lowercase. Typing edlin or EDLIN or Edlin would all run the Edlin editor. Similarly, you can type ten.c or TEN.C or Ten.C as the name of the file
C:\SRC>edlin ten.c
ten.c: New file.
*
Once inside Edlin, you’ll be greeted by a friendly * prompt. The interface is pretty minimal; no fancy “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 append command, by typing a 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.
*a
: #include <stdio.h>
:
: int main()
: {
: int i;
:
: for (i = 1; i <= 10; i += 1) {
: printf("%d", i);
: }
:
: return 0;
: }
: .
*
To view the text you’ve entered so far, use the list command by entering l at the * prompt. Edlin will print several lines above and below the current line. For this short program, the whole source file fits on one screen:
*l
1: #include <stdio.h>
2:
3: int main()
4: {
5: int i;
6:
7: for (i = 1; i <= 10; i += 1) {
8: printf("%d", i);
9: }
10:
11: return 0;
12:*}
*
Did you notice the * on line 12, the last line in the file? That’s a special mark indicating your place in the file. If you inserted new lines in the file, by typing i, Edlin would add those lines before this location.
Let’s update the program to print a “new line” after each number in the list. To do that, we’ll need to modify line 8 to include the “new line” character (the \t code in the C programming language). Edlin works on a line at a time, so you actually retype the whole line. Change line 8 by typing its line number; Edlin prints the original version and allows you to re-type the line in full.
*8
8:* printf("%d", i);
8: printf("%d\\n", i);
*
Edlin interprets backslashes in the way a programmer might. For example, to insert a literal tab character in your source file, use \t. If you want to insert a plain backslash, use \\ (two backslashes).
Listing the file contents afterwards shows the updated line 8.
*l
1: #include <stdio.h>
2:
3: int main()
4: {
5: int i;
6:
7: for (i = 1; i <= 10; i += 1) {
8:* printf("%d\n", i);
9: }
10:
11: return 0;
12: }
*
Let’s make one more change to the program, to add a comment that describes what the program does. This kind of “program” comment usually goes at the top of the file, before the rest of the program. In other words, we want to insert a new line at line 1. Do this with the 1i command:
*1i
: /* print the numbers from 1 to 10 */
:
: .
*
I also added an extra blank line after the comment, before the rest of the program. I could use the l command to list the file again, to check that my edit was made correctly, but we only need to verify the first few lines. Let’s specify a range of lines to list, from line 1 to line 5, with the 1,5l command:
*1,5l
1: /* print the numbers from 1 to 10 */
2:
3:*#include <stdio.h>
4:
5: int main()
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 to disk, then q to quit Edlin and return to DOS.
*w
ten.c: 14 lines written
*q
Really quit (Y/N)? y
C:\SRC>
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 # is a number (use . for the current line number, $ for the last line number), text indicates a text string, and file is the name of a file.
? | Show help |
| # | Edit a single line |
a | Append a line below the mark |
[#]i | Insert new lines before the mark |
[#][,#]l | List the file (starting 11 lines above the mark) |
[#][,#]p | Page (same as List, but starting at the mark) |
[#],[#],#,[#]c | Copy lines |
[#],[#],#m | Move lines |
[#][,#][?]stext | Search for text |
[#][,#][?]rtext,text | Replace text |
[#][,#]d | Delete lines |
[#]tfile | Transfer (insert the contents of a new file at the mark) |
[#]w[file] | Write the file to disk |
q | Quit Edlin |
e[file] | End (write and quit) |
To enter special characters in Edlin, use 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 |
Read the entire DOScember series and boot into vintage computing.
More from We Love Open Source
- 26 commands to get started with FreeDOS
- Turn off acceleration for an authentic retrocomputing experience
- How to write your first FreeDOS program
- How I run virtual machines with QEMU
- Why FreeDOS is a modern DOS
The opinions expressed on this website are those of each author, not of the author's employer or All Things Open/We Love Open Source.