The Emacs logo, licensed under GPLV2 or later

Emacs cheat sheet

Notes published the
4 - 6 minutes to read, 1110 words

Target audience

These notes are for those who want or need to begin to use Emacs and have zero experience with it.

It is also for those who need/want to use it right now and do not have enough time to learn how to use it properly.

Note 📝
This is a cheat sheet; it is not accurate, or complete, and omits a lot of details. But it should be good enough for a quick start.

Editing works more or less like on most other graphical editors (notepad, notepad++, Microsoft Word, Geany, Kate, Visual Studio Code, LibreOffice Writer, …​).

What makes Emacs "difficult" is that it has a lot of keybindings, which are different from most other editors, and the terminology used for describing them might be unique.

Why?

Why should you want to learn to use Emacs?

Keyboard shortcuts

Different programs use the same keybindings of Emacs.

For example in bash (unless configured otherwise) Ctrl+R is for searching in the history, and the key combination comes from Emacs.

Some interesting programs are written on top of Emacs

The first to come to mind are Org Mode and Magit

It is a complete working environment

Emacs is an OS that lacks a decent text editor

— unknown source

I’m using Linux. A library that Emacs uses to communicate with Intel hardware.

— Erwin
#emacs, Freenode

Emacs is highly configurable, and some people never leave it.

Checking emails, chatting, viewing pdf documents and images, browsing the web…​ it can all be done from Emacs.

Those examples (and the programs written on top of it) demonstrate how flexible Emacs can be, and that it can be adapted for more or less all workflows.

Saving file and closing the editor

If you want to save a file, type Ctrl+X, Ctrl+S (Ctrl+S is for searching forwards), this means, Ctrl+X followed by Ctrl+S. You can even type Ctrl+X followed by S while keeping Ctrl pressed.

The official Emacs documentation uses C- (Control) for denoting Ctrl followed by another key. Because this is a cheat sheet for beginners, I am not using the official notation, but the one most targetted people are more accustomed to.

If you want to close Emacs, you might notice that Alt+F4 works like for all other graphical programs in most environments. On Windows, sadly it does not work (but can be configured too, see the last section).

Ctrl+X,Ctrl+C is the cross-platform keybinding for closing Emacs.

Note that if there are unsaved changes to a file, it asks to save them.

Text Navigating

Just like editing, it is possible to navigate in a file with the arrows (, , , ), the mouse through clicks, and other keys (PgUp🠕, PgDn🠗, (Home), (End)).

Combinations like Ctrl followed by an arrow, like Ctrl+ should also work out of the box.

There are additional keyboard shortcuts for moving around:

  • Ctrl+A Go to the beginning of the line (equivalent to /Home).

  • Ctrl+E Go to the end of the line (equivalent to /End).

  • Alt+A Go to the beginning of the sentence.

  • Alt+E Go to the end of the sentence.

  • Ctrl+F Go forward by one character (equivalent to ).

  • Ctrl+B Go back by one character (equivalent to ).

  • Alt+F Go forward by one word (equivalent to Ctrl+).

  • Alt+B Go back by one word (equivalent to Ctrl+).

  • Ctrl+N Go to the next line (equivalent to ).

  • Ctrl+P Go to the previous line (equivalent to ).

  • Ctrl+V Move forward one screen (equivalent to PgDn🠗).

  • Alt+V Move backward one screen (equivalent to PgUp🠕)

Search and replace

  • Ctrl+S is for an incremental forward search

  • Ctrl+R is for an incremental reverse (backward) search

For searching with a regular expression:

  • Ctrl+Alt+S is for an incremental search with a regular expression

  • Ctrl+Alt+R is for an incremental reverse (backward) search with a regular expression

The Emacs documentation uses C-M-s and C-M-r respectively.

M- (Meta) stands for Alt followed by another key.

For searching and replacing a piece of text:

Alt+X replace-string ↵ Return <text to be replaced> ↵ Return <replacement text> ↵ Return

Note 📝
instead of typing out replace-string, use Tab ↹ to take advantage of the autocomplete feature.

For searching and replacing with a regular expression:

Alt+X replace-regexp ↵ Return <regular expression to be replaced> ↵ Return <replacement text> ↵ Return

Cut, copy and paste

  • Ctrl+Y for pasting (yanking in Emacs, like vi editors), not that it might not work when using Emacs from the command line

  • Ctrl+X, U (note: lowercase u, not Shift+U)

  • Use Ctrl+Shift or Shift followed by arrows (like in most graphical editors) or the additional keybindings for selecting the text

  • Alt+W for copying the selected text

  • Ctrl+W for cutting the selected text

Configurations

As Emacs does not come preinstalled on most systems, chances are you have it installed yourself. At that point, you might want to consider spending a couple of minutes configuring it a little bit.

The configuration file can be located at multiple places, I recommend using ~/.config/emacs/init.el.

Close Emacs just like other graphical applications

As mentioned, Alt+F4 does not work on Windows, while it does on GNU/Linux systems, at least with Gnome, KDE, Mate, and probably other graphical environments.

To enable Alt+F4 on all platforms, add the following line to the configuration file

(global-set-key [M-f4] 'save-buffers-kill-emacs)

In Emacs, "to kill" is the equivalent of "to close" in other programs.

Cua mode

Emacs can be configured to follow some "standard" conventions used by other graphical editors.

(cua-mode t)

Enables keybindings like Ctrl+X, Ctrl+C and Ctrl+V for cut, copy and paste. The keybindings for cut and copy only work after having selected some text, if not they would collide with other keybindings.

CUA mode also enables Ctrl+Z for undoing changes.

backup files

Either disable them with

(setq make-backup-files nil)

or move the backup location somewhere else

(make-directory "~/.cache/emacs-auto-save/" t)
(setq auto-save-file-name-transforms '((".*" "~/.cache/emacs-auto-save/" t)))
(setq backup-directory-alist '(("." . "~/.cache/emacs-backup/")))

Otherwise, every time a file is edited, Emacs creates a backup file (same file name, with ~ affixed) in the same directory.

Last but not least

The documentation and tour.

To quit a partially entered command, type use Ctrl+G


Do you want to share your opinion? Or is there an error, some parts that are not clear enough?

You can contact me anytime.