William Vaughn

Emacs wisdom from the internet

This is a collection of useful things I learned while searching the web for how to do something in Emacs. This blog is my effort to better remember and share these lessons.

The basics of Emacs copy/paste

Start visual selection C-SPC then navigate to end of selection.
M-w puts that text in the kill ring without deleting it. (Copy)
C-w puts that test in the kill ring and deletes it. (Cut)
C-y will “yank” that text out of the kill ring back into the buffer. (Paste)

Org Mode

Sparse tree search and tags

https://orgmode.org/manual/Sparse-trees.html https://orgmode.org/manual/Tag-Searches.html#Tag-Searches

C-c / m then the tag value.

Exiting a sparse tree is kind of weird but can be accomplished with C-c C-c and some Shift+Tab to cycle visibilities.

Narrowing Scope

Learn more: here

C-x n s To narrow a org mode to items under a single header

C-x n w To widen it back out. :praise:

Date and Time insertion

C-c ! Insert the current date

C-u C-c ! Will get you the current date and time!

Archiving DONE items

Learn more: here

C-c C-x C-a Archive a single item.

C-u C-c C-x C-s. Prompts for archives of items with status DONE. This can also be shortened to C-u C-c $.

Adding a CREATED property timestamp to an org item after it was made

  1. Add the CREATED property C-C C-x p , choose created, nil
  2. Go edit it and do C-u C-c ! to insert the timestamp.


Selecting and changing quoted strings.

Learn more: here


Replace from the current line to the end of the file: :.,$s/target/replacement/g

Replace in the region all occurrences: :'<,'>s/target/replacement/g.

You can do this by visually selecting and then pressing : to enter ex mode.


Remember to move around with { and }. Moving by code blocks/paragraphs.

Ivy Mode

C-M-j Don’t use the selection, just enter the text you’ve written!


M-x man Opening man pages.

ispell spell check

brew install ispell

M-x ispell to run the spell checker. Press A to accept a word for session. Use numbers in prompt at the top of the screen to select the suggestions.

Undo Tree

C-_ is undo. You can visualize the tree of things you undo. It’s C-x u. You can then move around that buffer, and the buffer you were editing gets previewed at each place in the undo tree.

Info mode

I cloned https://github.com/webframp/sicp-info and then I can read it in emacs by opening the .info buffer and running:

M-x Info-on-current-buffer

Python Debugging

Be in a file you want to run the debugger from. Or you can use M-x cd to change your working directory. To start the emacs pdb integration type M-x pdb.

This will prompt you in the minibuffer with:

Run pdb (like this?): pdb

You want to replace that pdb part with:

Run pdb (like this?): python -m pdb your_code.py


Run pdb (like this?): python -m pdb -m module.path.to.your_code

That is going to kick you into the pdb prompt. Now you need to type help and read the pdb docs.