Editing Text Files


This page tells you how to edit text files for this course. It covers these options:
  1. Use pico
  2. Use vi
  3. Use emacs
  4. Use a Graphical User Interface (GUI) Editor
  5. Use a DOS editor


Your easiest option is to use pico, the same editor that you will use to compose e-mail messages in pine. It's primary virtue is that there is virtually nothing to learn because it is so simple and because it always displays a menu of possible commands at the bottom of the screen.

The disadvantages to using Pico are (1) it doesn't include any features to make it easier to edit program files, (2) it does automatic word-wrap, which can mess up single line comments without your noticing it, and (3) it responds slowly to cursor movement keys.


Whatever Unix system you use, you will find vi there. It's much more powerful than pico, but you have to learn its commands. There is a tutorial program on qcunix1 to teach you the basics of vi: type "learn vi" at the shell prompt and follow the instructions.

There is a configuration option for pine that will let you use vi either as the default editor for composing messages or as an alternative editor that is invoked when you type "^_" in the Message Text part of the screen.


emacs is a very powerful editor that has the virtue of being programmable. You can program it to do just about everything you might want to do with a computer, it seems. The price you pay for all this power is a ton of complexity. Unless you already know it, I don't recommend trying to use it for this course.

GUI Editors

One disadvantage of pico, vi, and emacs is that you can't use the mouse to navigate through your text. If you run one of the X Window system editors, you can overcome that problem. On qcunix1, the X Window editor is called dxnotepad. How to use it is pretty self-evident once you get it started. In addition, if you start emacs when you are running the X Window System, it runs in its own window. (On some other Unix systems, such as Solaris, emacs under X has a full GUI interface, including drop down menus, a scroll bar, and full mouse support. This interface does not seem to be available on qcunix1 at the time of this writing.)

DOS Editors

You could use a DOS or Windows editor on a PC to edit your text files, and then transfer the files to your qcunix1 account using Kermit or (if you have Internet access from your PC) ftp. If you use this option, you need to know about the difference between how DOS and Unix store text files. Generally speaking, the differences will not effect your programs, but it is good to know about them anyway, just in case.

A Unix text file is a stream of bytes, with each byte containing the ASCII code for one character. The end of each line of text is the ASCII linefeed character <lf>, which has the numeric value of decimal ten (written in C++ as the character constant '\n' or as the hexadecimal constant 0x0A). Strictly speaking <lf> is a control code that causes the cursor to move down one line on the screen. There is another ASCII control code, carriage return <cr> (written 13, '\r', or 0x0D in C++) that moves the cursor to the left side of the screen. When you look at a text file on the screen, the operating system knows enough to output a carriage return every time is comes to a linefeed in order to make each line start at the left margin. DOS uses a different convention for storing text files. When you press <Enter>, a DOS editor puts both <cr> and <lf> into the file. (Macintosh, by the way uses the only other possible combination: it puts just the <cr> into the file when you press <Enter>.)

DOS editors normally mark the end of a text file with ^Z (hexadecimal 0x1A), but Unix programs such as the compiler normally ignore ^Z and <cr> characters when they encounter them. The only thing is, Unix editors try to display the carriage returns, and they show up as ^M characters on the screen. You can either delete them manually or ignore them if you encounter this problem. (In vi you can remove all <cr>s from a file by typing ":%s/^V^M//g" where ^V and ^M are control characters.)

Christopher Vickery
Queens College of CUNY
My Home Page