Emacs Cheat Sheet



Status: Finished. New content might be added at any time.
Abstract:
Whenever I work with GNU Emacs or read some documentation I make notes and add information to my various cheat sheets. Well, that was the past. Some time ago I decided to consolidate all that knowledge into a single page. This page is my collection for short notes and it also serves as a cheat sheet for information about GNU Emacs.
Table of Contents
GNU Emacs Hints and Notes
Special Emacs Subjects
Xft
mtty also known as multi-tty
Packages / Libraries
w3m
Dired
Image-Dired
How I process Static Images
TRAMP
artist-mode
pastie.el
python-mode
Notes, Functions, Variables and Settings
I want Emacs-like Behavior with GTK Applications
sort-numeric-fields
flush-lines
narrow-to-region
The grep Family
align-regexp
font-lock-mode
Collaboration with GNU Emacs
delete-duplicates respectively delete-dups
shell-quote-argument
file-newer-than-file-p
Info-goto-node
debug-on-error
file-attributes
call-process
C-M-h
C-x C-o
C-h p respectively M-x finder-by-keyword
M-x command-history
C-c C-l toggles font-lock-mode
list-colors-display
How to figure Faces and Text Properties of..
M-x list-faces-display
C-x respectively C-u C-x
count-lines-page
abbrev-mode
debug-on-signal
M-x locate-library RET <file_name> RET
M-x find-library RET <file_name> RET
Insert current date
C-u <an_integer> C-x f
What libraries are currently loaded
apropos.el
Transform text to lower/upper case
Development Versions of Emacs Packages
Automatize Updating to Development Code
Fetch up-to-date w3m Code
Fetch up-to-date BBDB Code
DebianGNU/* Notes
Leveraging debian-el
M-x apt-utils-show-package
M-x apt-utils-view-changelog
M-x apt-sources-mode
Dired
deb-view-dired-view

Emacs Command Cheat Sheet Standard Emacs Commands and Command Lines Marking Text to Delete, Move or Copy Command Keystroke Command-Line Mark the beginning of a selection C-@ or C-SPACEBAR M-x set-mark-command. Emacs Cheat Sheet Starting emacs from the Unix prompt% emacs to start emacs.% emacs filename to start emacs and load a file% emacs -nw.

GNU Emacs Hints and Notes

Of course, since we are in GNU Emacs country, there is always anotherawesome thing beyond the horizon but sooner or later folks usuallysettle on a decent amount of additional Emacs packages, commands,functions and self constructed stuff within their .emacs, .gnus and abunch of other libraries and files they came across during their past.

At least that is what happened to me and therefore I am going to notjust put such useful stuff at this page from now on but also (and thiswill take at least a year or so) break down all the fine things Ialready use on a daily basis into fractions and put them here — this,however, is quite a work intensive task since my emacs stuff (as ofnow (February 2011) is spread all over my system.

Special Emacs Subjects

Xft

mtty also known as multi-tty

Packages / Libraries

This subsection is about packages and libraries that I find worthmentioning explicitly. I am going to put information related tocertain GNU Emacs packages/libraries I use in this section. I considerthis packages useful or valuable to my daily work. However, I am notgoing to mention any piece of my .emacs here — just some things thatI find worthy to additionally mention here.

w3m is not just yet another web browser. It is text-based web browserwhich smoothly integrates with GNU Emacs and thus blurs the bordersbetween the Internet and the local machine. With w3m, what we get is aweb browser that directly integrates into a platform (Emacs) and thusallows to use all the Emacs magic even when surfing the WWW (WorldWide Web).

Sheet

The left image above shows w3m in the lower right window (currentlyvisiting http://plone.org/products/plone). The right image shows w3mthis time with two sessions. Also what can be seen in the upper rightwindow is ansi-term and how I create my screenshots. tsh is an aliasin my .bashrc. So far so good.. I am with up-to-the-minute w3m codefrom the upstream repository. Go here to see how I do it.

Well, how do I put it? Probably this one totally rocks describes itbest. I am a CLI (Command Line Interface) addict for several reasons(speed and power mostly). So, is there any way to be even faster withdaily tasks than using the CLI? Yes.. there is.. it definitely isDired.

Emacs Cheat Sheet

Dired, because over the years, I got used to traveling at hyperspace
speeds and whenever I drop out of hyperspace, back to sublight speed
(CLI) I get this fizzling noise in my left ear. It gets even worse if
I have to go on a planetary surface mission and move around on foot (GUI).
— random space traveller, stardate 2988.4

Dired has some add-ons like Image-Dired for example or Dired-X(evaluate (i.e. point behind form and then C-x C-e) (Info-goto-node'(dired-x) Top') in order to directly jump into the info manual ofDired-X).

Then there is also Wdired (yes, you know the trick by now.. evaluate(Info-goto-node '(emacs) Wdired')). Renaming files, changingpermissions etc. has never been easier before.. just hit C-x C-q ina dired buffer, rename/alter permissions/etc. and hit C-x C-c whendone to make all changes permanent.

Image-Dired

Being with Emacs not just means one can chat, write emails, writesource code, organize his schedule, manage his computer, etc. but italso means one has a powerful built-in image viewer and manipulator.Image-Dired is a facility for browsing image files. It providesviewing the images either as thumbnails or in full size, either insideEmacs or through an external viewer.

I pretty much live with the out of the box configuration forImage-Dired since all the keybindings and such is really good (atleast from my point of view). I just made a few keybindings for somefunctions I found myself using on a regular which justified to gavethem some shortcuts to invoke them. As usual, all my configuration forImage-Dired can be found in my .emacs.

My message for all the folks which still view/manage/mangle theirimages with some sort of heavy mousing approach — you guys mightreally stop wasting time and get to grips with Image-Dired, whererotating, moving around, resizing, building an XHTML gallery for somewebsite etc. becomes as simple as, for example, pressing L in order torotate original image 90 degrees to the left. One can also invoke (onthe fly) any program/command on any image from within Image-Dired. Forexample, note the fading background in the full-size image which Iaccomplished by running a vertical Gauss filter on the image directlyfrom within Image-Dired i.e. I simply triggered an Imagemagick commandon the image.

Do that with common GUI (Graphical User Interface) image viewers andat the end of the day your mouse will have gone at least a few milesplus you wasted a lot of time because you simply dealt with a stupidUI (User Interface).

More information on Image-Dired can be found in the GNU Emacs manual(within Emacs just hit C-h r) chapter (Info-goto-node '(emacs)Image-Dired'). Also, the Emacswiki has a page about it (it was calledTumme in the past but then changed its name to the current nameImage-Dired).

How I process Static Images

Of course, I also use the powers of Dired respectively Image-Dired toprocess my static images (photos). By processing, I refer to the whole

process chain from the point where I plug my all-in-one digicam viaUSB (Universal Serial Bus) to my computer until the photos (and othermultimedia stuff I came home with) are tagged, sorted, reviewed andfinally put into my multimedia archive.

This archive is nothing else than files on the file system — Idropped thesuper-but-folks-never-use-it-in-the-end-postgresql-for-private-multimediaapproach in favor of the easy-to-use file system approach. I did thatnot because PostgreSQL is bad (in fact I think it rocks!) but simplybecause the fact that Dired is made in order to perform whateveractions on a file system. Using Dired boosts my productivity withregards to a UI (User Interface) more than any GUI (Graphical UserInterface) or even CLI (Command Line Interface) could ever do.

Next to simply organizing my static images into categories implementedvia simple directories, I also tag my static images. This happensduring the input processing of images, while I review, mangle,reorder, etc. them and then put them into the archive.

The fact that I also tag my static images means that I get thepossibility for another, horizontal view on my archive. This view canthen be used (from within Image-Dired) to search, look up andreorganize things as needed. This horizontal view is more fine grainedand flexible compared to the usual vertical tree view that comes withthe file system tree. However, I got used to use those twoapproaches/views in a combined manner which really gets me greatresults from the beginning the whole way down to managing my archive.

The screenshot below shows a bunch of Dired buffers. This is at what Itypically look at during the input processing of static images rightafter I plugged my digicam. I made two nice udev rules as can be seenbelow. Those rules basically guarantee that my digicam shows up at thesame device nodes at any times and thus can be picked up by anotherscript (buffer at the topmost window below) which mounts the digicamstorage into my my computers local file system.

I got used to use

in order to copy the static images from the digicam onto my computerwhich is great since it retrieves the EXIF (Exchangeable Image FileFormat) data from the static images and uses that information togenerate the file name while it is copying the files.

TRAMP

After installing TRAMP (Transparent Remote Access Multiple Protocol)into our GNU Emacs, we will be able to access files on remote machinesas though they were local. Access to the remote file system forediting files, version control, and dired are transparently enabled.Our access to the remote machine can be with the rsh, rlogin, telnetprograms or with any similar connection method. This connection mustpass ASCII successfully to be usable but need not be 8-bit clean.

The package provides support for SSH (Secure Shell) connections out ofthe box, one of the more common uses of the package. This allowsrelatively secure access to machines, especially if FTP (File TransferProtocol) access is disabled. TRAMP can transfer files betweenmachines in a variety of ways. The details are easy to select,depending on your needs and the machines in question.

TRAMP also provides the ability to edit files owned by another userthan the current user on the fly e.g. we can edit files owned by root(/su::<path_to_file>) and just have to provide the root password oncefor each session. File permissions etc. do not change.

In fact, TRAMP can do a lot more than the afore mentioned. We canissue C-h i in order to start info (left window below) and read theTRAMP manual.

artist-mode

Artist mode, toggled by M-x artist-mode, lets us draw lines, squares,rectangles and poly-lines, ellipses, and circles with our mouse and/orkeyboard. It is extremely useful when inserting text diagrams orfigures into source comments (e.g. C++ source, Muse source, etc. Forexample, one might draw stuff like the below (took me under one minute..) which can then be used to post into IRC/email/howtos etc. Intothis, one might check pastie.el (see below).

There are somelinks and a nice screencast available.

pastie.el

Super useful to directly post from within Emacs into pastebin. Morehere and here.

python-mode

For python-mode and all other Python related information please visitthe section about GNU Emacs on my Python page.

Notes, Functions, Variables and Settings

This is a random collection of various settings, functions and othernifty Emacs tricks that I find either worth mentioning or just wantedto make a note on them to not forget them since they already served mewell in the past.

I want Emacs-like Behavior with GTK Applications

If we want Emacs-like behavior (keyboard shortcuts) with applicationslike for Firefox/Iceweasel, Pidgin, etc. then we can do

sort-numeric-fields

Comes in handy if you want to sort

into

flush-lines

Sometimes after I copy-paste code snippets from web pages into someEmacs buffer I get text with superfluous blank lines delimiting code.

Marking region and running M-x flush-lines RET ^$ RET quickly makes itbetter by removing those pesky blank lines. This is, of course, makessense only if pasted code does not contain blank lines you want topreserve.

narrow-to-region

You will love this! I use it for a lot of things e.g. narrow to regionand then use occur on that region. This works anytime for any commandi.e. there is no need for some command itself to feature<command>-on-region by itself. Just narrow to region and use anycommand you wish even when it has a built-in ..-on-region option.

The grep Family

They can save you a lot of time. Namely they are find-grep,find-grep-dired, grep, grep-find (same as find-grep) and


as well as

align-regexp

This interactive Emacs Lisp function was very handy for me during somelog files analysis. We mark the region, invoke align-regexp, provide aregexp and Et voilà!.. our region is aligned.

Example data from align-regexp help:


Let us say, that we want to align a region on the ( character. Forthat, we mark the region that we want to align and invoke the functionwith: M-x align-regexp RET ( RET. The result of such invocation willbe:

font-lock-mode

Sometimes e.g. for cut/yank actions, toggling font-lock-mode is veryhelpful.

Collaboration with GNU Emacs

It is possible to collaborate with GNU Emacs e.g. two persons editingone file.

delete-duplicates respectively delete-dups

Those two functions are used a lot here.

shell-quote-argument

file-newer-than-file-p

Info-goto-node

I make heavy use of the GNU Emacs built-in documentation system alsoknown as info since

  • it allows for easy copy and paste
  • I do not have to switch back and forth between Emacs and another application all the time
  • I am so much faster using info than for example the html counterpart of the same manual
  • etc.

Often, I write documentation or just want to refer to some informationwithin some manual or some page or so. Instead of doing it thecumbersome way most people do it

  • asking google
  • copy paste the URL over
  • probably touching the computer mouse (= annoying foreign substance)
  • etc.
Sheet

all I have to do is to insert (Info-goto-node '(emacs)Abbrevs') forexample. Then a person just has to position point after the closingparenthesis and hit C-x C-e and like magic, the info system getsstarted, the particularly manual (emacs) opens at the specific page(Abbrevs) — compare the time needed to do it the old-school way(searching, navigating, finding you are wrong, starting over again,..).

Those who write some notes or documentation can visit particular infopages, hit w (runs the command Info-copy-current-node-name) and thenpaste it into either a template ((Info-goto-node ')) they create usingsome GNU Emacs magic like insert for example or they just type itevery time it is needed.

debug-on-error

file-attributes


Use it like this

to get the mtime (modification time).

call-process

C-M-h

C-x C-o

A lovely thing indeed..

C-h p respectively M-x finder-by-keyword

Next to all those C-h f/v/k/m/b etc. there is another quite usefulkeybinding.

M-x command-history

C-c C-l toggles font-lock-mode

Toggle Font Lock mode. Font Lock is also known as syntaxhighlighting. For more info try C-h f font-lock-mode RET.

list-colors-display

If you would like to see what colors are available for GNU Emacs facestry M-x list-colors-display. What you get is something like that

How to figure Faces and Text Properties of..

M-x describe-face or M-x describe-text-properties will show youinformation about faces and text properties.

M-x list-faces-display


A picture says more than a thousand words

The left window above shows the current faces. The right window — ontop a ansi terminal, the buffer list in the middle and the window atthe right bottom shows the menu that can be used to edit a particularface that has been chosen from the left window — see the bottom of my.emacs (you find it on my main GNU Emacs page) how it looks like.

C-x respectively C-u C-x

A very useful command if you have problems with the display of somefonts and the like — use what-cursor-position to get informationabout the font etc.

count-lines-page

If you want to know how many lines the current page has plus how manylines are before (above) point and how many are after (below) point,then you might use

What you get is something like this in the minibuffer Page has 962lines (52 + 910). As can be seen, the current page (buffer) has atotal of 962 lines of which are 52 from current point position to thetop of the page and 910 from point to the bottom of the page.

abbrev-mode

Whenever I write text, I commonly use things like CLI (Command LineInterface) — an abbreviation (CLI) and its explanation ((Command LineInterface)). In fact, people use abbreviations very often and thus itis an ideal thing to be automatized in order to save time.

With Emacs there is the so called abbrev-mode which can be used to,for example just type cli and then use a keybinding (e.g. C-x a e) inorder to expand cli to CLI (Command Line Interface).

After using C-x a g to add new abbreviations one could either take alook at them (M-x list-abbrevs) or edit them (M-x edit-abbrevs) andwhen done, save them (C-c C-c). Take a look at theabbreviation mode info manual for more information.

debug-on-signal

M-x locate-library RET &lt;file_name&gt; RET

M-x find-library RET &lt;file_name&gt; RET

Insert current date

The sequence

inserts the current date

at point. Instead of date, you can choose any CLI (Command LineInterface) command — see for yourself

C-u &lt;an_integer&gt; C-x f

Normally the column width is set to 70 characters but sometimes youmight want to change that. I for example use it to write the wholetext in the Abstract area into a single line without a line break. SoI do something like C-u 5000 C-x f for example.


However, another way to accomplish the above would be to toggleauto-fill-mode like this

and use it like that

So, all you need to do is using C-c t a to toggle auto-fill-modebetween on and off. Whatever approach you choose probably depends onthe current situation..

What libraries are currently loaded

If you want to find out which libraries are currently loaded try

As mass unrest engulfs the U.S., we speak with attorney and political commentator Bakari Sellers, whose new memoir “My Vanishing Country” was just published. One of the central moments in the. Part memoir, part historical and cultural analysis, My Vanishing Country is an eye-opening journey through the South's past, present, and future. Anchored in in Bakari Sellers' hometown of Denmark, South Carolina, Country illuminates the pride and pain that continues to fertilize the soil of one of the poorest states in the nation. Bakari Sellers opens his heart and his mind in this memoir which is a love story, a tragedy and a history lesson all rolled into one. With raw emotion pouring onto the pages, Sellers effectively brings the gravitas of his on-air personality to print. Part memoir, part historical and cultural analysis, My Vanishing Country is an eye-opening journey through the South’s past, present, and future. Anchored in in Bakari Seller’s hometown of Denmark, South Carolina, Country illuminates the pride and pain that continues to fertilize the soil of one of the poorest states in the nation. “Bakari Sellers’ My Vanishing Country is exactly the book we need right now.The issues he raises are deeply personal and important to me. In his captivating memoir, Sellers. Bakari sellers my vanishing country.

Emacs Cheat Sheet Printable

or the variable load-history. It records lots of information aboutwhat libraries have been loaded in your session so far, what functionsand variables they each define, and what other libraries theyrequire. Try C-h v load-history - you'll get a very long list of verylong entries. In this regards, also take a look at the functionunload-feature, file-requires, file-provides and file-dependents.


For a list of loaded files you can take a look at

apropos.el

I forget basic Emacs stuff all the time so I need something to help meout..


This one is, bound to C-h a by default as can be seen. Thing is itjust looks for interactive commands. Use C-u C-h a to also search fornon-interactive functions.


If you want to search for variables use. Note the difference whenusing the C-u prefix.


You are looking for some value. Again, C-u makes a difference.


Now that is a neat thing indeed


Finally you could set

to non-nil anyway if you would like to.


For the more-confused ones a look at the source might provide somemore nifty tricks to find orientation again

a M-x find-library RET <.el that you are looking for> RET that is.


Transform text to lower/upper case

This is bound to C-x C-l (lower) respectively C-x C-u (upper). Also,you may put

Da vinci acrylic paint brushes. into your .emacs.


Development Versions of Emacs Packages

I have certain Emacs packages or just single files that even to old inDebianGNU/* sid (still in development). Because of that, I am usingthe up-to-date code of those packages which I directly pull fromprojects SCM (Software Configuration Management) systems on a regular.

Automatize Updating to Development Code

Best Emacs Cheat Sheet

The fact that development code is not available via APT (AdvancedPackaging Tool) requires one to take care one selves about acquiringthe up-to-date code.

In order to ease such repetitive tasks I decided to introduce a littleshell code magic. The idea is simple:

  1. First I am going to create some shell aliases in my .bashrc foreach of the development packages which downloads the changes froma projects upstream repository and merges them into my localbranch.
  2. When I have a working alias for each package I can chain themtogether and encapsulate all former aliases into a single one thatexecutes one by one e.g. alias ua='pa_1 && pa_2.. && pa_n'
  3. With a working ua (update all) alias I can then easily triggerthings with a cronjob or manually as needed.
  4. Finally some sane checks might be added i.e. how to handle errors.For example how to handle an error while downloading changes froma remote repository when the URL changed or the host isunreachable and the like.

Now, if you just take a look at my .bashrc you can see that 1 and 2from above are already done — 3 is not since I trigger e.g. murmanually every 3 days or so as I feel lucky about doing so —triggering via cronjob would of course be trivial. I did not careabout 4 so far since after testing all worked fine — I will probablyadd code when I run into problems.

Fetch up-to-date w3m Code

Yesterday (Tue Sep 4 2007) I switched to the multi-tty branch. Afterthat, Emacs did not start correctly (see how I start Emacs — I use analias in my .bashrc) i.e. Emacs complained that no w3m wasfound. After a while it turned out, that Debians current w3m-elpackage did not contain up-to-date w3m code so I needed to fetch fromCVS cvs -d :pserver:anonymous@cvs.namazu.org:/storage/cvsroot login &&cvs -z9 -d:pserver:anonymous@cvs.namazu.org:/storage/cvsroot co -dw3m-el emacs-w3m. Hint: hit RET on the anonymous CVS login — nopassword needed.

Fetch up-to-date BBDB Code

The development and release versions are available via Anon-CVS to theCVS tree at bbdb.cvs.sourceforge.net. To access the tree, log in withthe following command: cvs -d:pserver:anonymous@bbdb.cvs.sourceforge.net:/cvsroot/bbdb login. Thepassword is blank; just hit return at the prompt.

To check out the development version of the BBDB, use the followingcommand: cvs -d:pserver:anonymous@bbdb.cvs.sourceforge.net:/cvsroot/bbdb checkoutbbdb

DebianGNU/* Notes

This section is about GNU Emacs providing and/or leveraging featuresfor DebianGNU/*. The package

is such an example. It provides outstanding tools to GNU Emacs inorder to retrieve information from Debian or to do work on/withDebian. However, note that I also provide information on this websitewhich tells about common tools that help to develop and maintainsoftware for Debian.

Leveraging debian-el

This section shows some examples that leverage the powers that areavailable when using debian-el (install it with apt-get installdebian-el. This section can only scratch the surface of what ispossible. Nonetheless I will try to provide some depicting examples inorder to provide the first time reader with a notion of what can bedone as well as the guru with a nice time to linger-and-skim-overalready well-known things.

After installing debian-el, the first thing one might try is to fireup the info manual of debian-el — two choices..

  • first one: C-h i and then navigating dir to the entry for debian-el
  • second one: evaluate (Info-goto-node '(debian-el) Top'). Of course,the second one is way more like

M-x apt-utils-show-package

First, we show a packages information as most of you are probably usedto when you use the CLI (Command Line Interface) e.g. apt-cache show<package_name> or aptitude show <package_name>. Of course some of youmay use a GUI (Graphical User Interface) as well. I use GNU Emacsbecause I think it is the most comfortable, fastest and by farmightiest way to connect human brains to DebianGNU/*.

After issuing M-x apt-utils-show-package (or for the speed demonswhich we are — using the fancy-two-keys keybinding created) andentering a package name we get this (left image). The other two showjust more Emacs magic once we are in apt-utils-mode.

M-x apt-utils-view-changelog

Above we issued a command to show a packages information. Pretty muchevery time I take a look at the change-log. I am used to this althoughI use


To figure the change-log of the package debian-el which is still openin the right window (see above) all we have to do is to issue M-xapt-utils-view-change-log or even better since we are cool Emacsers,working at speeds others can only dream of, we might just hit v c andwhat we get is this (point must be in the buffer showing the packageinformation; right window in the current situation — see above)

How long would it probably take to do all that via the mouse or bychanging into the change-log directory of a particular package? Sure,most tools have either a switch or provide some other possibility toattain whatever information is needed but in the end my experience is,using an integrated environment like GNU Emacs has proven numerouslysuperior because that logical chaining of moving from A to B and backand from there on to C etc. and doing something that semantically fitsthe current needs of a human is always just a few keystrokes far frombeing completed.

M-x apt-sources-mode

A GNU Emacs mode that eases editing /etc/apt/sources.list Rick and morty. files a lot.

Dired

Dired has some neat features..

deb-view-dired-view

Emacs Cheat Sheets

deb-view-dired-view in action i.e. first image is on the left side, second in the middle.. Also, note the green rectangle, which is point in my case (customface).