EMACS FUNDAMENTALS
In order to do any Lisp coding at all, you need to be able to edit text (duh). With Doom Emacs, you have three options: Use Emacs keybindings, use Evil keybindings, or use Emacs as much as possible like VSCode or other editors you're likely familiar with. We'll call the last one Survival Mode. So far, you've been in Survival Mode.
- You've typed
C-zto enable EvilEmacs State, which enables editing using standard Emacs keybindings. - You probably turned off
lispy-modeto avoid confusing behavior. - You edited text as usual: type, mouse click around, scroll wheel up and down, click and drag to highlight text, copy/paste with the keybindings you already know, etc.
- You've used the top menu bar or mode line to browse commands you can use while editing Lisp files.
If you're still on the fence about this whole Emacs/Lisp thing, there is no shame in staying in Survival Mode. However, you probably ended up using some keybindings already for frequently used commands that you learned in the menu. This is the perfect start to learning Emacs–gradually incorporating more and more keybindings/functionality into your workflow as your power grows.
This chapter will help you increase your mastery of Emacs by introducing you to keybindings for many of the most common and useful functions in Doom Emacs, starting with text and Lisp editing, then moving on to buffers, windows, and projects.
SUPPORT LEVEL DISCLAIMER
None of the functionality here is necessary to continue this book. Instead, you should consider this chapter a reference to return to whenever you are ready to add a little more Emacs functionality into your workflow.
However, I won't be including any more references to the menu or using the mode line to navigate to and execute commands. For the rest of this book, I will refer to keybindings and give the names of the commands as well so that you can become familiar with the different packages and commands that are associated with different parts of Doom Emacs' functionality.
I will also assume that you are using Evil Normal State at least partially. If
you are in Emacs State and the keybindings aren't working, type M-x and type
in the name of the command I am referencing. Some commands may not have
keybindings in Emacs State, or they may be confusing.
Example: evil-delete-line will not have a keybinding in Emacs State and
org-kill-line in Normal State is bound to <deleteline>.
I won't be testing any of the keybindings in Emacs State. If you want to use
Emacs State exclusively you might be able to run some keybindings using
M-SPC instead of SPC, but not all commands have such alternative bindings.
I will only test keybindings in lisp-mode; other modes may have different
bindings, or commands that do similar but subtly different things may share
bindings in different major modes.
SETTING EXPECTATIONS
Learning Evil bindings + Doom Emacs exclusive bindings will take time. Expect to stumble around for two weeks, feel somewhat productive in two months, and proficient in about 6-12 months. As always, focus on the keybindings and features that seem most useful to the task at hand–learning Common Lisp–and learn more Emacs as you learn more Common Lisp.
TEXT EDITING
First, let's start with text editing.
By default, evil-mode is available and active in Doom Emacs. This means that
you have access to both Emac's default bindings as well as bindings typical of
Vim/Neovim.
If you don't already know how to use the Neovim keybindings, you can check out https://openvim.com or https://vim-adventures.com/. Both provide an interactive experience for learning the VIM text navigation keybindings.
evil uses several different editing states. The three most common are Normal,
Insert, and Visual. In Normal State, you navigate and run commands, often
starting with SPC. In Insert State, you can edit text. In Visual State,
you can select and act upon regions of text.
These states are set on a per-buffer basis. The state of the current buffer is displayed on the left side of the mode line.
Whenever a keybinding in this book mentions a keybinding starting with SPC, I
assume you are in Evil Normal State.
Inserting
Type i to enter Evil Insert State and type as usual.
Cutting/Copying/Pasting
To cut some text, you must kill it.
The simplest way to kill some text is to kill the entire contents right of the
cursor with D (lispyville-delete-line) while in Normal State.
To kill a whole line, type d d in Normal State.
You can kill single characters with x, single words with k i w or
M-backspace. You can kill the contents within some textual boundaries like ()
or "" with k i ( or k i quotemark. You can include the boundaries with k o
instead of k i.
To copy something, you must yank it.
Use y y in Evil Normal State to yank a line. You can yank a word with y i
w or a symbol with y i o.
To paste some text, type p in Evil Normal State, or s-v (or whatever
keyboard shortcut you're accustomed to using to paste text).
Marking Text
You can mark regions of text to work on using Visual State. Type v and then
navigate text to select it from where you first entered.
Marked text can be killed or yanked. There are plenty of other operations that you can do on marked text, but we'll save that for another time.
Simple Searching
You can search for some text in a buffer with SPC s s
(+default/search-buffer).
Aborting A command
Let's say you pressed SPC f, but you decided you don't want to continue. To
abort the command, press C-g (doom/escape).
It's common to accidently hit a key or combination of keys you didn't mean to.
If you are "stuck" inside some command, or in the middle of a keybinding, the
quickest solution is to press C-g a few times.
Undoing An Action
C-/ (undo-fu-only-undo) will undo the previous action. Doom also includes
the s-z keybinding, which is the same as undo in the browser, MS Word, etc.
Doing An Action Multiple Times
In Doom Emacs, if you press a number while in Normal State before running a
command, entering Evil Insert State, etc. Emacs will run the action the same
number of times as the number you typed.
If you don't know VIM/evil keybindings, you probably won't want to do this,
but you may accidently do so. For example, you may be in Evil Normal State,
press 9, enter Insert State and type something, then return to Normal State
with ESC, at which point you now have inserted the same text 9 times. It might
look something like this:
(+ 1 1(+ 1 1(+ 1 1(+ 1 1(+ 1 1(+ 1 1(+ 1 1(+ 1 1(+ 1 1)))))))))
The best thing to do in this situation is just undo and retype.
This functionality can be quite useful. For example, if you want to navigate
down 10 lines, you can type 10 j in Normal State to navigate down ten lines.
It also makes it easy to type decorative dividers in comments like this:
;; ==============================
Multiple Cursors
Type g z z (+multiple-cursors/evil-mc-toggle-cursor-here) to create a
cursor. Move your cursor and the one you created stays in place. You can create
arbitrary numbers of cursors. Once you've made all the cursors you need, you can
begin editing them by entering Evil Insert State.
If you need to pause the cursors, type g z t
(+multiple-cursors/evil-mc-toggle-cursors). If you need to undo the creation
of the last cursor, type g z u (+multiple-cursors/evil-mc-undo-cursor).
Multiediting
If you like multicursor editing in other editors, you're going to love multiediting in Doom Emacs. With multiple cursors, you can place cursors in arbitrary locations. The downside is that you need to move the cursor to each location you want to place the cursor. With multiediting, you can search and highlight text and edit all highlighted areas simultaneously. You can leave the highlighted regions and edit other text, then return to the highlighted region an
Place the cursor or mark a region. Type M-d
(evil-multiedit-match-symbol-and-next) to begin multiediting. If you type
M-d again, you will mark the next symbol or region that matches the first one.
You can continue that as many times as you want.
You can also match backwards with M-D
(evil-multiedit-match-symbol-and-prev).
While multiediting, if you press Enter, you will remove a match from being
edited. C-g to quit multiediting. Typing Enter again will toggle the match
back on.
After marking several matches, you can navigate directly between them with C-n
(evil-multiedit-next) and C-p (evil-multiedit-prev).
To unmark all matches and quit multiediting, type C-g (maybe a few times).
Searching & Replacing
When you want to rename a few instances of a symbol in a defun, multiediting
is the right tool for the job. If you want to rename a function throughout a
file, there is a better tool for the job: VIM search and replace.
To begin using it, just type : (evil-ex). How you proceed from there depends
on how sophisticated your search and replace operation needs to be. The simplest
case is replacing all instances of some text throughout the buffer:
:%s/TEXT TO REPLACE/TEXT TO REPLACE IT WITH/g
This search and replace tool is very powerful, but a full treatment is out of the scope of this book. A good place to learn more is the Vim tips wiki (https://vim.fandom.com/wiki/Search_and_replace).
Running Commands/Functions With No Keybindings
There are many commands that don't have keybindings. There are also many commands you don't know the keybindings for.
To find and run those commands, type M-x. A minibuffer will open with a list
of commands and a short description. If they have a keybinding, it will be
displayed in parentheses next to the command itself.
C-n will move the cursor down a line inside that minibuffer. C-p will move
the cursor up a line.
Quick Reference Table
Here's a quick reference table for everything covered in this section:
| Action | Emacs Binding | Evil Binding (Normal State) |
|---|---|---|
| enter Insert State | i | |
| delete character | x | |
| delete to end of line | D | |
| delete whole line | dd | |
| delete inner word | diw | |
| delete a word | daw | |
| delete inner parentheses | di( | |
| delete inner quotes | di" | |
| delete around parentheses | da( | |
| delete around quotes | da" | |
| delete with alt-backspace | M-Backspace | M-Backspace |
| yank (copy) line | yy | |
| yank (copy) inner word | yiw | |
| yank (copy) inner symbol | yis | |
| paste after cursor | p | |
| paste from system clipboard | C-v | s-v |
| enter Visual State | v | |
| search in buffer | SPC s s | |
| abort command | C-g | C-g |
| undo | C-/ | s-z or C-/ |
| repeat action N times | <number> then command | |
| multiedit: match symbol and next | M-d | M-d |
| multiedit: match symbol and prev | M-D | M-D |
| multiedit: toggle match | Enter | Enter |
| multiedit: next match | C-n | C-n |
| multiedit: previous match | C-p | C-p |
| quit multiediting | C-g | C-g |
| start ex command (search & replace) | : | |
| execute command (M-x) | M-x | M-x |
| navigate down in minibuffer | C-n | C-n |
| navigate up in minibuffer | C-p | C-p |
LEARNING MORE
Type M-x to open that minibuffer. Type describe. "Describing" is how you get
more information about something in Emacs. This feature makes it
"self-documenting".
C-h k will run the command describe-key. You will be prompted to enter a
keybinding you want described.
Type SPC f f in that prompt. It will tell you that the keybinding is for the
find-file function and lots of other information. It will tell you if there
are other keybindings, for example. You may prefer an evil binding or a Emacs
binding.
C-h m will run the command describe-mode. This will provide detailed
information about all of the modes that are active in a given buffer.
C-h b b will run the command embark-bindings. This will show all of the
bindings available in the current buffer. Useful especially for discovering Evil
keybindings that may only be one character long.
Type C-h i or SPC h i (info) to open the Emacs manual.

