Emacs (emacs): A popular UNIX Editor

Introduction

emacs is one of the most popular editors available to UNIX programmers. Emacs does have a menu bar across the top of its interface frame and this can help new users. This tutorial will introduce you to emacs and show you how to create, edit and save files with this powerful and popular UNIX file editor.

This tutorial will not teach you every emacs command that you will ever need to know. Rather, the goal of this tutorial is to introduce you to some of the commands that are available.

This tutorial uses the notation [Ctrl-x] to indicate that you should hold the [Ctrl] key down while you press the "x" key. Then, release both keys. Do not type the "[" and "]" characters, just type the key combination indicated. If the character indicated is in upper case like in [Ctrl-X], you must hold the [Shift] key down while the character is pressed.

The notation [Ctrl-x-c] to indicates that you should hold the [Ctrl] key down while you first press and release the "x" key and keep holding the [Ctrl] key down while you then press and release the "c" key. Then, release the [Ctrl] key. As before, do not type the "[" and "]" characters, just type the key combination indicated. Double quotes are used to indicate that an entire line of text should be entered as shown.

I assume that you know how to login, logout and open xterm windows in UNIX.

Objectives

Topics

  1. Create your own quick reference sheet for Emacs. (5 minutes)
  2. Start the Emacs tutorial. (5 minutes)
  3. Learn about Emacs buffers: how to create and switch between them. (5 minutes)
  4. Improve your (edit) Emacs cheat sheet. (10+ minutes)

Overview

When you create or open a file with Emacs, you are in the edit mode by default, where you can delete characters, words, lines, etc. and perform other types of edits as well. To add information, you just type the text you want to enter. It will be inserted at the point of the cursor.

In this tutorial you will learn the purpose of several [Ctrl] commands. After completing this tutorial, you will have your own quick reference sheet that you can print and add to as you learn more commands.

Create your own Emacs quick reference sheet

Creating your own quick reference sheet of Emacs commands will give you practice using Emacs to create and edit text files as well as providing a document for you to refer to if you forget a particular command that you remember learning.

Practice Exercise #1

  1. Open an xterm window if necessary.
  2. At the command-line prompt, type emacs emacs_reference.txt and press Enter. You are now in edit mode and any keys that you type will be inserted into the current buffer (file).
  3. initial view of emacs shows menu
  4. Type the following into your file. If you make a mistake, you may backspace and retype the line correctly or just continue. If necessary, you will be able to correct any mistakes later.
    
           Emacs Quick Reference Sheet
           ------------------------
    
           Ctrl-x Ctrl-c    - to exit Emacs.
    
    

    Your file should now look like this:

  5. Type [Ctrl-x][Ctrl-s] to save your work.
  6. Type [Ctrl-x][Ctrl-c] to exit emacs. You are now back at your shell prompt and your work has been saved in the file emacs_reference.txt

Emacs Tutorial

Practice Exercise #2

  1. Open an xterm window if necessary.
  2. At the command-line prompt, type emacs emacs_reference.txt and press Enter to open the file you created in topic #1.
  3. Reopen the file and type [Ctrl-h] and release, then type a t.
  4. This starts the Emacs Tutorial. Complete this tutorial to learn more about Emacs and what capabilities are available.

Buffers in Emacs

The main edit screen is really just one of several "buffers" available to you in Emacs. You will want to become familiar with creating and switching between multiple buffers while you write your programs and other files.

Don't forget to add the Save command (see above) to your reference sheet.


       Emacs Quick Reference Sheet
       ------------------------

       Ctrl-x Ctrl-c    - to exit Emacs.

       Ctrl-x Ctrl-s    - to save the current buffer.

       Ctrl-h t         - to start Emacs tutorial
                          (don't hold the Ctrl key down while typing the 't')

Practice Exercise #3

  1. List all available buffers.
  2. Type [Ctrl-x Ctrl-b] to list all currently available buffers.

Modify (edit) your edit quick reference sheet

Practice Exercise #4

Follow these steps to modify your emacs_reference.txt file. You should review the the commands explained in topic #2 and try the new ones suggested.

  1. Open an xterm window if necessary and open the "emacs_reference.txt" file you created in topic #1.
  2. Type [Meta-x] goto-line [Enter] 4 to move to line #4 of the file.
  3. Add the following new reference lines to your file by typing:
    [Ctrl-u] - type to undo a command

    If you've made any mistakes, just continue. You'll learn additional editing commands in the next exercise.

Your reference sheet should look like the following perhaps with a few typing errors that you'll correct in the next exercise.

       Emacs Quick Reference Sheet
       ---------------------------

       Ctrl-x Ctrl-s - save changes
	   Ctrl-x Ctrl-c - exit emacs

Practice Exercise #4

In this exercise, you will correct any typing mistakes that you may have made during the previous exercises. Since, it is not possible for me to know exactly which typing errors you may have made, this exercise will be different from the earlier exercises. Instead of a step by step approach, I'll just provide a list of emacs commands that can be used to edit characters in your file. Be sure to try each of them as you edit your "emacs_reference.txt" file.

Add the text editing commands to your reference file

  1. Add each of the following text manipulation commands to your reference file.

Use the man pages for more information

In this topic you will view the on-line programmer's manual page for emacs. These pages explain each of the options that can be used when starting emacs.

Summary

In this lesson you have learned how to create, edit and save text files using emacs, one of the more popular editors available to UNIX programmers.

As you work in emacs and learn new commands, be sure to add them to your quick reference sheet so that you will be able refer to them in the future.

Vocabulary

Buffers

The temporary space that is used to edit file information before it is written to the file.

Editor

A program used to create program and data files.

Emacs Tutorial

The program help that is provided as part of the Emacs installantion.

Where to Get More Information