High Performance Computing High Performance Computing University of Southampton


What is EMACS

"…an advanced, self-documenting, customizable, extensible real-time display editor"

Useful addresses



Windows 3.x, 95 and NT


Manuals and Reference Materials






Important Features



Getting started with Emacs


To create or modify a file called file.junk, type this unix command:

emacs file.junk

Use the following once inside emacs:

Arrow/cursor keys

move around (*)


delete character (or linebreak) before cursor

Control-x Control-c

exit emacs (offers to save changes to file)

(*) Note: If your Arrow keys don't work, contact a local expert to configure things so they do. Otherwise, you can use the following Control-characters: f (forward) b (back) n (next-line) p (previous-line)

More Beginner Stuff

Control-x u



cancel command (use this if you ever get "stuck")

Note: if you see a file with ~ at the end of the name, this is a backup copy of the previous version of your file.

Advanced Beginner

(Note: ``ESC v'' means press (do not hold down) Escape key and then press v .)


(or Pg Down on some kbds) scroll down one screenful


(or Pg Up on some kbds) scroll up one screenful


beginning of line


end of line

ESC < (or Home on some kbds)

beginning of file

ESC > (or End on some kbds)

end of file


fill paragraph (wrap into as many lines as needed)

Control-_ (Ctrl-Shift-Hyphen; Ctrl-/ on some keybds)

undo (hold down to repeat)


delete next character


kill (cut) line (repeat or hold down as needed)


yank (paste) killed text (then ESC y for previous)


search forward (press twice to repeat last search) (**)


search reverse (press twice to repeat last search)


cancel action (e.g. search)


refresh/redraw screen and center current line

Control-x 1

un-split screen if it gets split in two

(**) Note: Control-s is the standard way to search forward in emacs, but we prefer to always use Control-\ in its place because Control-s cannot be used over certain terminal connections. If Control-\ does not work, consult your local expert who can configure things so it does.


Any time you are told to use Control-s, you should be able to use Control-\ in its place, as mentioned above. Also Control-^ in place of Control-q.

There is a tutorial to learn things not mentioned here, including more ways to move around, editing multiple files, using the online help system, etc.: Control-h t

Use C-h i in emacs to browse or search the emacs manual in info


(C-x means Control-x; M-x means Meta-x (or ESC x))

M-x overwrite-mode (Insert key on some kbds)

toggles overwrite mode

C-@ (Control-Shift-2) (or C-SPACE on some kbds)

mark start of region


kill (cut) region (from mark to current point; C-y yanks it)


save (copy) region (from mark to current point; C-y yanks it)


query-replace one string by another (type ? for help)

M-x what-line

show current line number

M-x goto-line

go to a line number

C-x 2

split screen into 2 emacs windows

C-x o

switch to other emacs window

C-x b

switch to another buffer

C-x k

kill buffer (without saving changes if any)




What are tags?

A tags table is a description of how a multi-file program is broken up into files. It lists the names of the component files and the names and positions of the functions (or other named subunits) in each file. Grouping the related files makes it possible to search or replace through all the files with one command. Recording the function names and positions makes possible the M-. command which finds the definition of a function by looking up which of the files it is in.

Creating Tags Tables

The etags program is used to create a tags table file. It knows the syntax of several languages, as described in the previous section. Here is

how to run etags:

etags inputfiles...

The etags program reads the specified files, and writes a tags table named `TAGS' in the current working directory. etags recognizes the language used in an input file based on its file name and contents. You can specify the language with the `--language=name' option.

Selecting a Tags Table

Emacs has at any time one selected tags table, and all the commands for working with tags tables use the selected one. To select a tags table, type M-x visit-tags-table, which reads the tags table file name as an argument. The name 'TAGS' in the default directory is used as the default file name.

All this command does is store the file name in the variable tags-file-name. Emacs does not actually read in the tags table contents until you try to use them. Setting this variable yourself is just as good as using visit-tags-table. The variable's initial value is nil; that value tells all the commands for working with tags tables that they must ask for a tags table file name to use.

Finding a Tag

The most important thing that a tags table enables you to do is to find the definition of a specific tag.

M-. tag RET

Find first definition of tag (find-tag).




This allows you to navigate remote file systems and code without having to explicitly deal with ftp

Opening a remote file



This is transparent and occurs by the normal mechanism





.emacs files (lisp!)

Setting function keys

(global-set-key [f1] 'rmail)

(global-set-key [f2] 'mail)

(global-set-key [f3] 'gnus)

(global-set-key [f4] 'folding-mode)

(global-set-key [f5] 'compile)

(global-set-key [f7] 'goto-line)

(global-set-key [f8] 'replace-string)

(global-set-key [f10] 'ispell-word)

(global-set-key [f27] 'beginning-of-line) "Home"

(global-set-key [f28] 'backward-paragraph) "Up"

(global-set-key [f29] 'scroll-down) "PgUp"

(global-set-key [f30] 'backward-char) "Left"

(global-set-key [f31] 'other-window) "Center"

(global-set-key [f32] 'forward-char) "Right"

(global-set-key [f33] 'end-of-line) "End"

(global-set-key [f34] 'forward-paragraph) "Down"

(global-set-key [f35] 'scroll-up) "PgDn"

(global-set-key [C-f27] 'beginning-of-buffer) "c-Home"

(global-set-key [C-f33] 'end-of-buffer) "c-End"

(global-set-key [C-f33] 'end-of-buffer) "c-End"

Reading mail in emacs

; mail, Rmail

(setq mail-archive-file-name "~/Mail/sent")

(setq mail-header-separator "*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*")

(add-hook 'mail-mode-hook



; ***********************************************************************

; Set up alias expansion as soon as typed in

(add-hook 'mail-setup-hook 'mail-abbrevs-setup)

C mode

; Using cc-mode

(fmakunbound 'c-mode)

(makunbound 'c-mode-map)

(fmakunbound 'c++-mode)

(makunbound 'c++-mode-map)

(makunbound 'c-style-alist)

(autoload 'c++-mode "~/emacs/cc-mode" "C++ Editing Mode" t)

(autoload 'c-mode "~/emacs/cc-mode" "C Editing Mode" t)

(setq auto-mode-alist

(append '(("\\.C$" . c++-mode)

("\\.cc$" . c++-mode)

("\\.hh$" . c++-mode)

("\\.yy$" . c++-mode)

("\\.c$" . c-mode)

; ("\\.h$" . c-mode)

("\\.h$" . fortran-mode)

("\\.y$" . c-mode)

("\\.u$" . fortran-mode)

("\\.F$" . fortran-mode)

) auto-mode-alist))


Highlighting code

;Hilighting !

(cond (window-system

(setq hilit-mode-enable-list '(not text-mode)

hilit-background-mode 'light

hilit-inhibit-hooks nil

hilit-inhibit-rebinding nil


(require 'hilit19)



Saving desktop and places in files

;(Uso de saveplace.el y desktop.el)

(require 'saveplace "~/emacs/saveplace")

(setq-default save-place t)

Fortran 90 mode

; Set up Fortran 90 editing mode (sjc)

(setq load-path (append load-path '("~/emacs")))

(autoload 'f90-mode "f90"

"Major mode for editing Fortran 90 code in free format." t)

(setq auto-mode-alist (append auto-mode-alist

(list '("\\.f90$" . f90-mode))))

(setq f90-mode-hook

'(lambda () (setq f90-do-indent 3

f90-if-indent 3

f90-type-indent 3

f90-program-indent 2

f90-continuation-indent 5

f90-comment-region "!!$"

f90-directive-comment nil

f90-indented-comment "!"

f90-break-delimiters "[-+\\*/,><=% \t]"

f90-break-before-delimiters t

f90-beginning-ampersand t

f90-smart-end 'blink

f90-auto-keyword-case nil

f90-auto-hilit19 t

f90-leave-line-no nil

f90-startup-message t

indent-tabs-mode nil


;;The rest is not default.

;; (abbrev-mode 1) ; turn on abbreviation mode

;; (f90-auto-fill-mode 1) ; turn on auto-filling

;; (if f90-auto-keyword-case ; change case of all keywords on startup

;; (f90-change-keywords f90-auto-keyword-case))






Last updated 29-Oct-97. Maintained by SJ Cox