The Ultimate Doom Emacs Cheatsheet
Table of Contents
- A few tips for Emacs newbies
- Command Abbreviations
- General
- Projects with Projectile
- Dired
- Buffers, Windows and Basic Navigation
- Installing Packages using org-super-agenda as an example
- Quick, horizontal movements with evil-snipe
- Multiple cursor in Emacs with evil-multiedit
- Org Mode
- Magit
- LSP-Mode
- Terminal
- File Tree
- Capturing
- Org Roam
- Code Folding
- Latex
- Bi-directinal texts (RTL languages)
- Sources
- What to learn
[0/3]
| 🔗 Home | 🔗 posts |
A few tips for Emacs newbies
- Use EmacsClient and set up a daemon. Your Emacs experience will improve a lot and you will save a lot of time.
- For better experience, use Emacs’s inner file manager.
- Get LSP up and running. It will turn Emacs into a fully-featured modern IDE. Emacs supports LSP for almost every language.
- Try to avoid terminal version of Emacs when possible.
- Use Doom Emacs’s built-in helps to understand how things work under the hood and change them to suit your needs.
SPC h ktells you how key combinations translate to Emacs commands.SPC h whelps you find keyboard shortcuts for different commands.SPC h vlets you see what’s inside variables and change them.SPC h ftells you about functions and where they are defined.SPC h b bto see a list of all keybindings
- Github doesn’t render org files very well. It’s best that you clone this repository and open it in Emacs.
- See other files in this repository as well. Currently additional instructions for Go, and Python are also offered. If there’s anything missing, or you can suggest a better workflow, make sure to contribute.
- Doom Emacs is a great emacs distro, but for a deeper understanding of Emacs, try setting up a minimal version of Emacs yourself using this guide or similar ones.
Command Abbreviations
C- “Control” keyM- “Alt” or “Option” keyS- “Super” or “Command” keySPC- “Space” key
General
SPC f sfor saving the current fileSPC :for entering a commandSPC q qto close EmacsSPC f Dto delete this file
Projects with Projectile
SPC p pto open a projectSPC SPCto open a file in a projectSPC o pto open the file explorerSPC o Eto open the shell (eshell) in fullscreenSPC o eto open the shell (eshell) in a popup windowSPC f rrecently visited filesSPC p rrecently visited files in a projectM-x projectile-discover-projects-in-directoryto find projects within given folder using ProjectileM-x projectile-discover-projects-in-search-pathto find projects in the folder defined by theprojectile-project-search-pathvariable using Projectile
Dired
- Dired (Directory Editor) is how you interfaces with a directory
- Press
C-x dto open dired. - Use
RETto go to a folder or open a file. - Use
-for going one folder back - Use
+for creating a new directory - Use
dto mark the files for deletion, pressxto delete. - Use
Mto change permissions - Use
oto sort by modes. - Use
Oto change the owner. - Use
mto mark anduto unmark files or directories. Uto unselect all- Use
tto invert the selection. tto switch between files and directories- Use
Cto copy. - Use
Rto move. - Move with
h,j,k,l - Toggle
(for simple view SPC .to create or find a file- Use either arrow keys, or hold
C-withh,=j=,=k=, andlto choose between options.
- Use either arrow keys, or hold
*to select all directories.Ccopy to another windowRmove to another windowdired-do-what-i-mean-targetset to trueito edit file/dir name
Buffers, Windows and Basic Navigation
Buffers
- Buffers are a special concept in emacs they can be terminals, files, directories, etc
SPC b bto open another buffer- workspace buffer
SPC b Byou can see all the bufferSPC ,to switch buffers (its an alias)SPC SHIFT ,to switch to all buffersSPC b XYou can create a scratch bufferSPC b sto save and name it
Windows
SPC w vwindow split verticallySPC w swindow split horizontallySPC w wto switch windowsSPC w qto close window, frame, quit EMACS if last frameSPC w +andSPC w -to increase and decrease window heightSPC w >andSPC w <to increase and decrease window width- You can use vim motion keys to navigate between open windows for example
SPC w Hmoves the window to the left. - Windows are panes in your screen
Workspaces
SPC TAB nNew workspaceSPC TAB NNewly named workspaceSPC TAB [Previous workspaceSPC TAB ]Next workspaceSPC TAB dRemove workspaceSPC TAB RRestore last sessionM-1Switch to workspace 1M-2Switch to workspace 2 and so forth.
Installing Packages using org-super-agenda as an example
SPC f pto open the config.- To add a package, add the package to
.doom.d/package.el - Then close and
doom refresh - Then go to
.doom.d/config.elto configure the package def-package!is a macro you can use to configure packagesspace h helpyou can look up method man pages:initis used for setting the package up:configto set configuration after the package has been initialized:afterlets you set which package it should load after
- You can use
:after!to configure packages that are already there
Quick, horizontal movements with evil-snipe
Inline navigation
fand then the letter you want to navigate to.,will go backward;will go forward after that “find”
tto find and move cursor to the character before what you’ve searched.vputs you in visual mode. You can select text by withv t some-char-you-navigate-toorv f some-char-you-navigate-to;to jump to the next find,to jump to the previous onesto snipe
Long distance navigation inside the file
- Evil-snipe lets you go to all the occurrences in your document
g s SPCto use avy and going to a certain word in file.tis the same thing except for a character you want to jump to before the one you insertsto do a double character search- Evil-snipe will remember your last search so
,and;will navigate ForTto go backwardsg s SPCand then select the letter that avy gives you to navigate to that spot- These letters are on your home row so they are easy to click
SPC h vfor variable, to set the avy variable to search all open windowsavy-all-windowslets you search in all windows open.
- You can remove a word with
g s SPC select-one-letter x select-the-removal-spot- You can use
Xto stay in your original spot of search
- You can use
- You can go
g s space select-one-letter i select-the-correction-spotto correct the spelling of the search- Install ispell on your OS first
- You can
yanka word from one place to another withg s SPC select-one-letter y select-the-correction-spot-to-paste - Use
tto “teleport” the word from one place to anotherg s SPC select-one-letter t select-the-correction-spot-to-teleport
Multiple cursor in Emacs with evil-multiedit
- Using evil-multiedit (known as multiple cursors in other IDEs) you can make selections and then edit those selections simultaneously. To do this uncomment
multiple-cursorsin yourinit.el. M-dwill select the current word, press this again and it will find another occurrenceM-Dwill find an occurrence upward- You can use a visual selection to select multiple words as well.
Rwill select all occurrences.CTRL nfor next selectionCTRL pfor previous.- Exclude matches with
RET - You can make an edit and the changes will be reflected to all the selections.
Org Mode
Basics
- Org mode gives you the ability to structure your document
*for a h1**for an h2 and so on- You can
TABa section to fold a subtree (hide it) - You can use
SHIFT TABto cycle through folded states CTRL returnto create a headline of the same typeM-arrow uplets you shift the position of the sectionM-hpromotes a headline to the next levelM-ldemotes- You can create lists
- one
- 2
- wooo
- 3
Links, Hyperlinks and more
SPC m lto add a link to an org page- You can add
::to specify a heading or a line number - You can paste http links as well
- You can “link” some text with specific code
SPC m lelisp: (+ 2 2) when you click the link, emacs will evaluate the expression - Show My Agenda
- List Files in directory
Defining custom Link Types
Linking to words & Bookmarks
SPC n lstores a link to a particular headline
Code Snippets & Babel
SPC i sfor inserting code snippetsExample:
(+ 2 3 4 5)
C-c C-cto execute the code.SPC m 'to edit inside the babel in another buffer.- Results will show up in a
##+RESULTSheader - This feature is called Babel
- One snippet can consume the output of another snippet
- You can create your own snippets in the following directory:
~/.doom.d/snippets/
Task Management
- Create a task by prefixing any heading with
TODO DONEmeans the task is done- You can create your custom key words by changing this variable:
org-todo-keywords- remember you can get to your variables through
SPC h v(M-x counsel-describe-variable) These values are already set in Doom:
((sequence "TODO(t)" "PROJ(p)" "STRT(s)" "WAIT(w)" "HOLD(h)" "|" "DONE(d)" "KILL(k)") (sequence "[ ](T)" "[-](S)" "[?](W)" "|" "[X](D)"))
- remember you can get to your variables through
SPC m tto change a status of a todoSHIFT leftandSHIFT rightcan be used to change the status of a todo as well.- If you finish a task with a command, org mode will add a date that you “closed” the task.
SPC o a tto open the agenda -> todo listqto quitorg-agenda-filesis a variable you can set to filter which files agenda searches for todos in.
Priorities for Tasks
SHIFT upandSHIFT downwill toggle the priority of tasksorg-fancy-prioritiesgives you fancy looking priorities
Marking Tasks with Tags
- Tags can be attached to any headlines
SPC m qto tag a headline- Example:
- TODO play more games :fun:
- Tags are hierarchical so nested headings will be tagged with the parent header tag
org-tag-sparce-treewill search for headings that only have a specific tag
Setting a property for a task/headline
SPC m ois used for setting a property.
- Marking Headlines with Categories
- You can use categories to change the label in agenda view.
- Org-Habits
- If you want to keep track of your habits using org mode, you can set the
STYLEproperty to habit.
- If you want to keep track of your habits using org mode, you can set the
Lists
- Two types of lists, ordered and unordered lists
SHIFT rightandSHIFT leftcan be used to change the type of lists.
- You can also change an unordered list by changing the first item to 1. and then typing
C-c C-cand vice versa.
Checkboxes
[ ]This is still todo[-]This is in progress[X]This is a done task
You can see how many are done with a “cookie” [1/2]
[-]Task 1[X]Task 2- You can do this by adding
[/]to the heading and pressingC-c C-c - You can’t assign a tag or a priority
Misc
C-c C-zto insert a note for a heading in org mode.
C-c C-cto insert a tag for a heading in org mode.
Magit
- Magit is enabled by default in Doom Emacs’s init.el
SPC g gshows Magit status page- Most commands are done from the status page
- Use tab to expand headlines in the status page
?in Magit’s status page for a nice list of available commands and help,qto close this help page- Open diff view for a file with
TAB - Press
sunder “Unstaged changes” to stage a changeuto undo a changecto commit
b sfor branch and spinoff to create another branch, rewinding the commits you made to masterb bto switch branches
Git Commit Flow in More Detail
t tto create a tag, default place is the commit you are currently selectingVto select a change in a diff andxto discard that change.sto stagecto commit, you canqto quit the commit screenPto push and thenpto your remote oruto a another remote
Magit with Forge for Issuing Pull Requests - Emacs
- Forge is installed in emacs doom
@for forge- Set up forge with
M-x forge-pull- the first time you will get a token from Github
@ c pto create a pull request with forge- select the base branch
- then select the target branch
- then provide a short description
CTRL c CTRL cto finish the pull request
- Now there will be a
pull requeststab
LSP-Mode
LSP related
lsp-update-serverselect a language server to update.lsp-workspace-folders-addto interactively set a folder as an LSP workspace.lsp-workspace-folders-removeto interactively unset a folder as an LSP workspace.lsp-workspace-restartto restart your workspace. Especially useful after activating a virtual environment.
While coding
SPC c cto run a compile command (or a test, or any other command in the current directory)SPC c Cto repeat the command aboveSPC c djump to var/func/… definitionsC o(evil-jump-backward) Go back to your last position in the jump listC i(evil-jump-forward) Go forward in the jump list
SPC c Dsee references to var/func/…SPC c eto evaluate the current buffer or region (when nothing is selected, equivalent to runningSPC c cand writinggo run+ the file name.)SPC c fsee references to var/func/…SPC c kjump to documentationSPC c rrename all references and definitions for the var/func at point in all project filesSPC c ssend to REPLSPC c xsee all LSP diagnosticslsp-ui-imenuto navigate definitions in your codeflycheck-list-errorsto see the errors detected by LSP.
Terminal
- Set up vterm in your init.el file.
SPC o Tfor opening vtermSPC o tfor opening vterm in a popup window
File Tree
- Set up neotree or treemacs in your init.el file.
SPC o pfor opening neotree or treemacs
Capturing
SPC Xto capture (the new thing gets captured to a single file but that’s fine since we can easily refile it.)SPC m r rto refile
Org Roam
These keybindings only work after installing org-roam. To install org-roam edit your init.el file and add (org +roam2) in its designated place. Watch this video to understand what org-roam is.
SPC n r fFind an existing node or create a new one.SPC n r iInsert a link to another node.SPC n r rToggle backlinks paneSPC m m o tAdd a roam tag.SPC m m o aAdd a roam alias.
Code Folding
Code folding helps with code readability. First, make sure fold is not commented in your init.el file then move your cursor to the definition of a class or a function and try the following:
z aToggle the fold at point.z mClose all the folds.z rOpen all the folds.z jNext folded region.z kPrevious folded region.
Latex
- TBD, for now see Michael Neuper’s blog post which has videos as well.
Bi-directinal texts (RTL languages)
- First uncomment
bidiunder:inputininit.el - If your cursor moves at the wrong direction, see this evil-mode bug and toggle evil-mode by pressing
C-zif neccessary. - To enable the bidi-mode everywhere and change the font of Persian/Arabic texts, you can use the snippet below:
(+bidi-global-mode 1) (setq +bidi-want-smart-fontify nil) (set-fontset-font t 'arabic "Sahel") ; Works for Persian as well