Overview of Emacs

Christian Rössl



About me

  • I'm a lecturer and researcher with the Visual Computing group at FIN / OvGU
  • Doing Computer Graphics with focus on Geometry Processing and Scientific Visualization
  • This includes
    • Programming in C/C++, Matlab, Ruby, …
    • Writing text, e.g., scientific papers, in LaTeX
    • Doing presentations usually in LaTeX
  • I need one editor that helps to get things done


  • What is Emacs?
  • Why Emacs?
  • How can Emacs help me to get my work done?
  • Goals of this talk

Emacs is for real programmers…


because it has M-x butterfly

So it must be hard

  • Typical editor learning curves?
  • Is it worth the pain?
  • Well, given the alternatives… except vi ;-)

Historical note: editor war

  • Sort of a tie?
  • Seems like, if I look at my students… ;-)

Important note

  • The keyboard is your best friend
  • I encourage you to try Emacs
  • But please don't use a German keyboard layout,

    or you will probably dislike Emacs

  • Real programmers use US or other fancy keyboard layouts! ;-)
  • Holds similarly for other editors/tools

Apropos keyboard

  • Emacs uses keyboard combos
  • Control C-
  • Meta M-
    • usually Alt key
    • and/or ESC key used as a sticky key
  • Don't try to memorize commands now!
    • Use a reference card later
    • Commands are fairly consistent in different contexts

Starting Emacs

  • Just start emacs
  • Disappointed because vi starts up faster?
  • Emacs can run as a daemon: emacs --daemon
  • emacsclient starts instantly
  • Can have multiple servers

Emacs in the console

  • Emacs can start in the console
  • start explicitly emacs -nw
  • or start Emacs, e.g., in an ssh session
  • You may want to pimp your terminal first, e.g,
    export TERM=xterm-256color

Documentation and Help

  • Emacs comes with an extensive manual
  • Emacs is self-documenting C-h
    • tutorial C-h t tutorial
    • C-h f FAQ
    • C-h k describe key
    • C-h f describe function
    • M-x apropos
    • M-x help

Emacs user interface

  • Frames
  • Windows
  • Buffers
  • special: minibuffer
  • Point, mode line, menu bar


  • On graphical displays, Emacs may show multiple frames
  • Emacs term frame = window
  • Emacs uses the term window differently


  • Emacs can split a frame into many windows
  • Examples
    • delete this window C-x 0
    • delete all other windows C-x 1
    • split vertically C-x 2
    • split horizontally C-x 3
    • switch C-x o
    • grow window C-x ^
  • Note: similarly for frames: C-x 5 ...


  • All text resides in buffers
  • Each buffer has a unique name
  • Basic interaction
    • Select another buffer C-x b
    • list all buffers C-x C-b
    • kill (delete) a buffer C-x k
  • Emacs' user interface is built on buffers
  • You will never have a dialog popping up!
  • Instead use the minibuffer

Basic editing

  • Visiting, creating, saving files
  • Editing text
    • moving the cursor (point)
    • goto line/column/position
    • erasing (killing) text
    • undo
  • Numeric argument (prefix)
    • Repeat things N times M-N
    • Invert command C-u
  • Repeating the last command
  • And more, see basic editing commands


  • The minibuffer lets you edit a line to enter, e.g., a
    • file name
    • buffer name
    • command
    • search pattern
  • Understand the minibuffer as a "universal dialog"
  • Submit and quit with Enter
  • Cancel and exit with C-g
  • Remember C-g!

Search and replace

  • Emacs' basic search and replace is powerful

    and can be used efficiently

  • Incremental forward and backward search
  • Search and replace strings
  • Search and replace regular expressions
  • Emacs defines its own regex syntax

Entering commands

  • Emacs lets you enter commands
  • No need to assign/remember keys for rarely used commands
  • M-x lets you browse commands
  • Even more fun with smex (see also ido) or eshell


  • The mark delimits a region of text
    • set mark C-space
    • set mark and swap point C-x C-x
    • mark all
  • Mark semantic regions (words,sentences,paragraphs,…)
  • Operate on region (kill,copy,undo,replace,fill,…)

Mark ring

  • The mark ring remembers positions of marks
    • push marks
    • push w/o activating C-space C-space
    • pop and more point C-u C-space
    • mark ring per buffer
  • Pop from Gobal mark ring C-x C-space

Killing and yanking

  • First of all forget CUA (though Emacs can emulate)
  • Powerful variant of copy&paste
  • The kill ring stores multiple entries (default: 60!)
  • Kill means cut and copy into kill ring
    • kill line C-k
    • kill region C-w
    • and more
  • Yank means paste and pop from kill ring
    • Yank last kill C-y
    • Replace last yank by earlier kill M-y
    • and more


  • Emacs can manipulate rectangles, e.g.,
  • Kill C-x r k
  • Copy C-x r M-w
  • Yank C-x r y
  • and more…


  • Emacs registers store
    • positions
    • text
    • rectangles
    • window configurations
    • numbers
    • file names
    • bookmarks

Registers: examples

  • Save position C-x space r in register number r
  • Restore/Jump to position C-x r j r from register r
  • Copy text in region to register C-x r s r
  • Insert text from register C-x r i r
  • Store number to register C-u number C-x r n r
  • Increment by number C-u number C-x n + r
  • Insert number from register into buffer C-x r i r

Keyboard macros

  • Keyboard macros are simple and powerful tools
  • F3 start macro definition
  • F4 end definition or execute macro
  • Append to macro
  • Run on each line in region
  • Keyboard macro ring
  • Associated counter: enumerate things
  • Query action similar to search&replace
  • Save and edit macros

Major and minor modes

  • major mode
    • determines editing behavior
    • define hooks to, e.g., install minor modes
    • e.g., LaTeX-mode
  • minor modes
    • optional
    • change behavior
    • any number minor modes
    • e.g., flyspell-mode
  • mode line shows modes (among others)

Setting major modes

  • Emacs selects major modes automatically, e.g.,

    depending on file extension

  • This behavior can be customized
  • File modes can be chosen explicitly
    ; -*- mode: Lisp;-*-
    • set Emacs variables
    • evaluate Emacs Lisp

Modes and structure

Modes, modes, modes

  • The remainder of this talk will be an overview of modes
  • Before we get to that
    • Customization
    • Packages: easy installation
    • And I should at least mention Emacs Lisp

Emacs Lisp

  • Emacs is implemented in Lisp (and some C code)
  • It defines its own Lisp dialect: Emacs lisp (elisp)
  • Files
    • source .el
    • compiled "byte code" .elc

Why should I care?

  • Emacs can be extended by elisp libraries
    • Customization sets variables and hooks,

      see, e.g., ~/.emacs

    • Modes are implemented as sets of functions
    • M-x evaluates lisp functions
    • You can even play M-x tetris

      (It's a mode, of course.)

  • Actually, Emacs is a Lisp IDE ;-)
  • Packages are elisp libraries


  • Emacs 24 (finally) comes with a package system
  • ELPA Emacs Lisp Package Archive
  • Before
    • use your OS's package manager (well-known packages)
    • install manually (all others)
  • Mind installation per user
  • It was never easier to install new modes!


  • Emacs (modes) can be customized easily
  • M-x custmmize general customization
  • M-x customize-themes select color theme
  • Advanced customization via Emacs Lisp


  • Configuration file typically ~/.emacs
  • Own extensions typically in ~/.emacs.d/
  • Emacs Lisp
  • M-x customize writes elisp code
  • Look for examples on the web!

How to install packages

  • Preliminaries…
    (require 'package)
    (add-to-list 'package-archives
      '("marmalade" .
    (add-to-list 'package-archives
      '("melpa" .
        "http://melpa.milkbox.net/packages/") t)
  • M-x list-packages

Interaction with files and buffers

Open files and switch buffer

Find patterns

Full featured tools

Shell interaction

Modes useful for editing

Somewhat exotic

vi emulation

  • viper
  • evil (vi is the editor of the beast because VI VI VI = 666)
  • You can play VimGolf in Emacs!
  • Watch at emacsrocks.com

Revision control and related

  • Emacs supports major SCM tools such as git
  • magit and/or egg
  • plus various blame modes
  • diff-hl highlights changes
  • ediff compare and patch files and buffers


Info and man

  • M-x man
  • M-x woman ("man w/o man")
  • M-x info

More programming


Markup and related

  • org-modeYou must try this!
  • HTML, markdown



Few suggestions for getting help and new ideas

Learn Emacs: a one page HowTo


Emacs shortcuts


About this presentation

  • I used Emacs and org-mode to structure the presentation
  • For HTML export, I used org-reveal that is based on reveal.js
  • Find source and the exported HTML here