Introduction
Two editors are used on the Computer Science Department's UNIX systems: vi and emacs.
The next two sections explain vi and emacs. Each section contains the following: a general description, how to learn it, how to get into it, and some of its commands.
Vi is a visually oriented text editor that's based on ex, a line editor that's available on most UNIX systems.
You can learn vi by doing the following:
To use vi, type the following command:
vi file
If the file you designate exists, it will be opened, and the contents will be displayed. If the file does not exit already, vi will open a file with the specified name. Vi has two modes: command and insert. When you start vi, you're in command mode. In command mode, vi accepts commands like the ones listed later in this section (commands to move, delete, save, etc.). In insert mode, vi accepts everything you type as text.
If you're in command mode, you can enter insert mode by typing a command like i, which inserts text starting at the cursor (there are others -- see the list of commands). If you're in insert mode, you can enter command mode by pressing the escape key.
Emacs is an advanced, self-documenting, customizable, extensible real-time display editor. Emacs was written by Richard Stallman of the Free Software Foundation. Emacs is mostly written in Lisp, with some C for efficiency.
Emacs is WYSIWYG (what you see is what you get), updated frequently, has features like text filling, auto-indent, viewing 2+ files, deals with characters, words, lines, paragraphs, sentences, pages. The user can change the definitions, rearrange the command set, and create new commands (programs in Lisp) online (don't need to create a new version).
Welcome to Emacs. Learning Emacs may seem a daunting task, but spending a few minutes learning Emacs, can save you many more in the future. Emacs is an extremely powerful editor and many of tasks you now do from the command line and using different applications can be done from inside of Emacs.
The section contains a brief tutorial on some of the basic operations of Emacs, so you can get started quickly and learn the more powerful features later.
To start Emacs type `emacs' and an optional file you wish to edit then press return. That's it!
If you didn't specify a file when you started Emacs you can open one after you enter Emacs by typing C-x C-f. This means hold down the control key and then press the x and f keys and release the control key. You will be prompted for a file name at the bottom of your Emacs screen. Enter the file name you wish to edit and press return.
There are three different ways to move around in your file: Control keys, the mouse and, if they are enabled, the arrows keys on your keyboard. Below are the control keys, with which you can move around in your file. Any other keys you press will be inserted as text in your file.
C-f forward-char C-b backward-char C-n next-line C-p previous-line C-a beginning-of-line C-k kill-line C-e end-of-line C-d delete-char C-g keyboard-quit C-h help-command C-l recenter C-o open-line C-r isearch-backward C-s isearch-forward C-t transpose-chars C-v scroll-up C-@ set-mark-command C-w kill-region C-y yank C-z iconify-frame C-_ undo
To save your file press C-x C-s
To exit Emacs press C-x C-c
If you get stuck by hitting the wrong key combinations you can press C-g to abort. This will terminated almost any command. You should read the section on getting help before you get started.
Command completion is a usefull time saving feature of Emacs and can save you many keystokes and works in most contexts. One usefull example is: when opening a file you don't have to enter the whole name, just type the first letter or first unique letters and then press the tab key. Emacs will fill in the rest for you. If there is more than one file with the same first characters, pressing the tab key again will open a buffer window with a list of the file names which have those first characters.
If you are using Emacs19, read the section on Emacs19 first. Many of the commands you do by entering keystrokes can be done using menus.
When you see M- in the documentaion it means press the ESC key first. On some systems the ALT key has the same effect.
To execute a command in Emacs use M-x and then the command name.
When you edit a file in Emacs, it is stored and edited in a buffer and when you save your file you are actually saving a buffer. Buffers can not only contain files they can also be used for a wide variety of purposes. Among these is storing and displaying the information generated by help commands and utility lisp programs such as mail handlers or gnus, the Emacs news reader.
These are the most used buffer commands.
To list all the buffers use C-x C-b this is bound to the list-buffers command.
To kill a buffer use C-x k this is bound to the kill-buffer command.
Buffers in Emacs are displayed in windows. When you first start Emacs you see only one window, you can display more than one window by dividing the display either vertically or horizontally.
Use C-x 2 to split a window vertically or use C-x 5 to split a window horizontally.
Delete a window with C-x 0 and move to another window with C-x o.
An Emacs reference card is available in the tutors room. Complete documentation is available in the info system under Emacs. Printed version of the same documentation is also avialable.
One of the big advantages of Emacs over other editors is the extensive availability of on-line help. To acess on-line help use ESC-? or C-h depending on which is enabled in your system. Here is a list of the help functions and a brief explanation of them.
Emacs19 is the X-based version of Emacs and is mouse-sensitive. Many new feature have been added. Read Emacs News in the help menu for a list of these.
Menus have been added and can be accessed by the menu bar or by holding the control key and clicking a mouse button. These menus can also be customized.
A scroll bar is on the side of the frame and by clicking on it with the mouse you can move around your buffer.
Multiple frames can be added with new frame.
The mouse can be dragged to mark a region and with the edit menu you can cut and paste like many commercial wordprocessors. You can also cut and paste between Emacs and the rest of your X terminal screen.
Emacs19 is still unsupported software at PSU and is located in the /usr/local/uns/bin path. Some parts of the .emacs initialization file don't port to emacs19.
(display-time)
(setq-default version-control t)
(setq-default auto-save-interval 50)
* display-time displays the time, system load factor and a flag to indicate unread mail on the mode line (in addition to the other stuff).
* version-control set to true allows for versioning: if you edit the file prog1.c, then you will end up with a previous version, prog1.c. and the current file.
* auto-save-interval saves your file after specified number of keystrokes. (Causes short delays, but I value my work.....)