|
Academic and Research Computing
QUICK STUDY #23 March 2001 Using the UNIX emacs editorWhether you are writing a program, writing a paper, or editing a mail message, you will need to create, store, retrieve, view, and edit files. Emacs is one of several UNIX text editors available on RCS. You can use emacs on an RCS workstation or via a remote connection.If you are using a workstation, you'll find that many of the key sequences described in the sections below are available on the emacs menu, making it easy to perform a number of common tasks. Starting emacsTo create a new file or to view an existing file, enter the following command at a UNIX prompt:
emacs filenamereplacing filename with the name of the file. From a workstation, it is a good idea to append an & to the above command. Doing so makes emacs run ``in the background,'' allowing you to work in other windows without quitting emacs.
Entering TextTo start your work, simply start typing. To insert text before existing text, move the cursor to the appropriate place and type. Text to the right of the cursor will move over. Press Return or Enter at the end of a line to insert a new line after it. (Because emacs does not have word wrap by default, you should do this at the end of each line you type.)To insert a new line before an existing line, press Return at the beginning of the line. To split a line in two, press Return in the middle of the line. To join two lines, move the cursor to the beginning of the lower line and press the Delete key to join it to the preceding line. Deleting TextYou can use the Delete key or the Backspace key to delete the character that appears before the cursor. Additional delete functions are:
Moving Around in the FileYou can move the cursor by using the four arrow keys on the keyboard. To scroll up and down, you can use the PageUp and PageDown keys. In addition, the Home and End keys move to the beginning of the file and the end of the file, respectively. If you are logged in remotely, however, you may find some of these keys don't work. You can always use the following key combinations:
Undoing Mistakes (CTRL-x u)To undo the command you just issued, press CTRL-x u.Canceling a Command (CTRL-g)If you started a command you don't want to finish, mistype a command, or otherwise get confused, you can bail out by pressing CTRL-g. Sometimes, depending on the trouble you're in, you may need to press it more than once.Searching for Text (CTRL-s and CTRL-r)Press CTRL-s to start a search. After the cursor moves to the bottom of the screen, type the text you want to search for. (Case is ignored.) Emacs will start searching as soon as you type the first character. To search for the next occurrence, type CTRL-s again. To stop searching, press the Enter/Return key. To search backwards in the file, use CTRL-r instead. Remote users on some systems may find that CTRL-s is used by communications software to control data flow. (If you find that pressing CTRL-s freezes your session, press CTRL-q to unfreeze it.) If you have this conflict, the easiest way around it is to use CTRL-r for searching. If you keep pressing it, the search will wrap around.Replacing Text (ESC x replace-string)To replace every occurrence of some text with new text, first move the cursor to the top of the file and press ESC x. When the cursor moves to the bottom of the screen, type:
replace-string (Press Return.) Type the text to be replaced and press Return. Then type the new text and press Return. Automatic Line Wrap (ESC x auto-fill-mode)If you want to avoid pressing Return at the end of each line of text, you can instruct emacs to do it for you by turning on ``auto-fill-mode.'' First press ESC x, then, when the cursor moves to the bottom of the screen, type
auto-fill-mode (Press Return.) This is a toggle command: if you do this again, it turns off auto-fill-mode.
Online Help in emacsThese are only a few of the emacs commands. The table below shows some ways to get online help.
Exiting emacs and Saving a File (CTRL-x CTRL-c)To leave emacs, press CTRL-x CTRL-c. Emacs will ask whether or not you want to save the file. Enter yes or no. On a workstation, you can save changes without leaving emacs by pressing CTRL-x CTRL-s. Remote users might have a conflict with CTRL-s, as noted above.
|