ASTR 3520: Introduction to Unix Text Editors


Editing text in unix is different from normal word processing. In word processing, you generally are writing for a human audience and constructing sentences. You often have the benefit of a spellchecker and a syntax that isn't too concerned with mistakes (for example, if you have only one space after a period instead of two, no one is going to mistake your meaning). In text editing, however, you are writing for a computer that doesn't speak the same language, can't correct your spelling all the time, and will become uncooperative when any mistakes are made.

One of the most significant differences between word processing and text editing is that line numbers become significant. In a word processor, your text is automatically wrapped to the size of the screen - if you keep typing, it will automatically start a new line for you. In text editing and unix command processing, each line is treated as an independent command, and each line has to be separated by the enter key (also called a "carriage return" because of what it did on typewriters).

For the above reasons, it is convenient to use a different set of tools for text editing. The most common tools in unix are vi and emacs, but these editors have an extremely steep learning curve and will appear completely unintuitive on first use, perhaps similar to every first experience you have on unix. If you don't want to take the time to learn these tools in detail, there are simple editors that are less powerful and similar to word processors (but better because they respect the way unix treats lines and formatting). Two that are available on the cosmos network are nano, which is an updated version of pico, and nedit, which is the only graphical editor listed here (a graphical editor means it is in a different screen from the xterm you open it in). All of these can be used on the command line by simply typing "[editor name] [filename] (&)", e.g. "vi login.cl". The (&) is if you want to open it in a different screen, which can only be done with nedit or the graphical version of vi, called gvim.


If you DO want to learn vi, here is a very brief introduction and some links:
In vi, to edit text, you must be in "insert mode". This can be achieved by pressing "i" or "a". Insert mode is just like being in notepad or nedit; all you can do is enter and delete and move around in text.
If you are not in text mode, you will be in "command mode". Command mode is much more powerful, but also incredibly complex. There are a few essential commands you must know, and a few that you should be careful about. First, be careful about pressing any of these keys: xcsd. They all delete text in some fashion. The "u" key undoes the most recent change. If you press ":", you enter a command line within the editing window (you should see a : in the bottom left corner of the screen). The most important commands are ":w", which writes your changes (saves them), and ":q", which quits the program. ":wq" saves changes and quits.

Links:
"Best of VIM" tips: an extremely rich collection of commands
VI Cheat Sheet
VI Cheat Sheet 2
"Beginner's Guide To VIM" suggests running "vimtutor" - I agree
Introductions to VIM (google search)

An introduction to emacs I don't use emacs, so I can't recommend any other handy tools, but google is usually quite good about these things.


ASTR3520 home

Page written by