Unix Text Editors

From AstroBaki

Jump to: navigation, search

[edit] Short Topical Videos

[edit] Reference Material


A Beginners Guide to Emacs

Nicholas Szandor Hakobian; updated by Carl Heiles University of California, Berkeley, Undergraduate Radio Astronomy Laboratory Version 2, nick@ugastro.berkeley.edu

So What Is Emacs?

Emacs is a text file editor in Unix environments. This includes our lab which runs a variant of Unix called Solaris, and other, more readily available operating systems such as Linux. You can use emacs to quickly edit a simple text file, as an editor for your IDL source code, or as a nice front end to typesetting documents in , the required typesetting utility in this class. This document will outline the basics of using emacs.

The Basics


Most of the programs that you will be using on these systems will be started from the command line. To begin a new document, simply navagate (via the Unix command line) to the directory where you want the file to be and type:

emacs something.txt &

Where something.txt is the new file that you wish to create, or the old file that you wish to update. After a few moments, a new window will popup with a blank screen that you can type into. You can use the mouse to navigate the menus at the top. See table 1 for information on what the different menu options do.


Contains information about the currently open files in this instance of



Contains basic commands for opening, saving, and closing files.


Contains advanced functions for doing things like version control.


Contains cut, paste, and spell checking capabilities of emacs.


Contains search and replace functions.


Advanced editing functions.


LaTeX specific functions. Only appears when the filename you are

editing ends with .tex.


IDL specific functions. Only appears when you are editing a filename

that end with .idl or .pro


Emacs’ extensive help and configuration area.

Emacs Menu Items

Now that you have emacs open you can type something in the text area. In the next section we will save the file.


In Emacs, saving a document is as simple as π. You can click on the Files menu, then click on Save Buffer... You can also save by using the keyboard shortcut C-x C-s. In the interest of simplifing your life, this document will concentrate on the usage of keyboard shortcuts in using emacs.

Keyboard Shortcuts

Just about every aspect of emacs can be accessed and configured with keyboard shortcuts. This means that to work on a document, you rarely need to move your hands away from the keyboard and use the mouse. This increases productivity, and just makes things easier. All the keyboard shortcuts that I mention in this document will be summarized at the end.

All keyboard shortcuts are represented in a format like C-x C-f. When you see a -, that means you hold the key that comes before and after the - down at the same time. The capitol C however, does not correspond to the letter c, but rather the control button (abbreviated CTRL) on the keyboard. So, if you see C-x C-f, that means press and hold the CTRL button, then press the x key, then press the f key, then release the CTRL button. If you see something of the form C-x d, then that means to press and hold the CTRL button, press x, release CTRL, then press d. I think you get the picture. Similarly, M represents the ALT button.

In some of the menus, you will see keyboard shortcuts that are labelled as M-%.

On the Sun workstations that corresponds to the \Diamond , and works identically to the CTRL key. On non-Sun workstations this key is simulated by pressing ESC then CTRL-whatever.

Some basic keystroke Shortcuts:
C-x C-f - Open a file
C-x C-s - Save file
C-x C-c - Close Emacs

C-space - Start Selection
C-w - Cut ("kill") selection
M-w - Copy selection
C-y - Paste ("yank") selection
C-k - Kill a line

C-x C-2 - Split window horizontally
C-x C-3 - Split window vertically

C-a - Move to the beginning of a line
C-e - Move to the end of a line

Cutting, Pasting, and Navigation

In Emacs cutting and pasting is simple, yet slightly different from what you may be used to. To do it using keystrokes only:

  1. Select and cut the block of text by
  1. moving the cursor to its beginning, type C-spacebar.
  2. using the arrow keys, move the cursor to its end abd type C-k.
  3. Paste the block by
  1. moving the cursor to where you want to paste
  2. type C-y .

To do it using the mouse: Select the text with your mouse and the double right click in the selection. To paste, move the cursor to where you want to paste and click the middle mouse button.


Emacs has nice integration. If you start a file with the ending .tex, Emacs will automatically load up in a mode to highlight special characters and special modes to make life a little easier. Emacs also has a couple modes to automatically compile files and display the result in xdvi (refer to the handout if none of this makes sense to you. Below are the basic shortcuts.

Compile file

C-c C-f

View file in xdvi

C-c C-v

- Emacs commands

IDL Integration

Emacs also has a nice mode for integrating with IDL. For the purposes of this lab, we will only need to use the highlighting features of Emacs. This checks to make sure that you have matching parentheses, that you correctly close if...then...endif statements, and will color special keywords separately from other commands. It is recommended that you execute your IDL files from the IDL command prompt.

Personal tools