Emacs

Table of Contents

Resources

History

Unsorted things

  • Config file placed in ~/.emacs.d/init.el
  • Dismiss welcome screen with q
  • Save program with <C-x> <C-s>
  • Cancel an action with <C-g>
  • Close emacs with <C-x> <C-c>
  • Start editing a new file with <C-x> <C-f>
  • Check variable name with <C-h> v
  • Repeat the last minibuffer command with <C-x> ESC ESC
  • List recent command history with <M-x> list-command-history
  • Suspend emacs with <M-x> suspend-emacs, resume with fg in parent process
  • Check what keybinding of a command is with <M-x> where-is (<C-h> w also works)
  • Files ending with ~ are Emacs backup files. Can get rid of them with (setq make-backup-files nil) according to this, but will leave them in for now...
  • Check recent keystrokes with <M-x> view-lossage (also bound to <C-h> l)
  • Show line numbers with <M-x> linum-mode
  • Toggle line wrapping with <M-x> truncate-long-lines
  • Change color schemes with <M-x> load-theme
  • To indent a selection, use the <Tab> key
  • Replace all with <M-x> string-replace
  • Replace some with <M-C-%>
  • <F10> brings up the menu option, <Esc> to cancel
  • To convert from DOS to unix, do <C-x> <C-m> f. Source
  • To look up scheme symbols use <C-h> S
  • Kill an unresponsive scheme process with <M-x>delete-process "*scheme*" in the scratch buffer

Packages

  • Install packages by adding the snippet given here, then run list-packages:
    • Press Enter on the package you want to install
    • Use d to mark any obsolete package for deletion

Buffer management

  • Buffer documentation
  • Multiple windows

  • In one view, cycle between buffers with <C-x> RIGHT/LEFT

  • Close a frame with <C-x> 0
  • Split a buffer:

    • Horizontally with <C-x> 2
    • Vertically with <C-x> 3
  • Make current buffer to only window with <C-x> 1

  • Clear persisted desktop with <M-x> desktop-clear

  • Kill buffer with <C-x> k bufname RET. Empty bufname for current buffer

List buffers with <C-x><C-b> (opens up the Buffer Menu as a split window)

  • d marks a buffer for deletion (to be killed)
  • x performs flagged deletions
  • q to close menu

Interbuffer

  • Toggle between buffer windows with <C-x> o
  • Set bookmark with <C-x> r m
  • Jump to a bookmark with <C-x> r b
  • List bookmarks with <C-x> r l
  • Can also use marks: <C-u><C-u> to set a mark without starting the highlight of the region, and then <C-u><C-space> to jump back to it.

Dired

Can be used as a file browser

Open Dired with <C-x><d>

  • Navigate with <S-ArrowKeys>
  • m marks a file
  • ^ to go up a directory
  • d to mark file for deletion
  • R can be used to either rename or move a file
  • x to execute deletion
  • + adds a new directory
  • g to reload the dired buffer
  • <C-x><C-q> goes into editing mode

Ido

Stands for Interactively Do Things

Open ido with <C-x> b to navigate to open buffers

  • MRU is the first entry
  • <C-s> (next) and <C-r> (previous) to move through list
  • <C-x> <C-b> and <C-x> <C-f> work as usual

Intrabuffer

  • Incremental search forward with <C-s>, repeat with <C-s> as well
  • Incremental search backward with <C-r>, repeat with <C-r> as well
  • Start of line with <C-a>
  • Go to a particular line with <M-g> g
  • Go to a particular column with <M-g> <TAB>
  • End of line with <C-e>
  • Start of paragraph with <M-a>
  • End of paragraph with <M-e>
  • Start of word with <M-b>
  • End of word with <M-f>
  • Next line with <C-n>
  • Previous line with <C-p>
  • End of buffer with <M-<>
  • Start of buffer with <M->>
  • Make current line center of window with <C-l>
  • Move cursor to middle of screen with <M-r>
  • Scroll up a window with <M-v>
  • Scroll down a window with <C-v>

S-Expressions

  • Move forward over a balanced expression with <C-M-f>
  • Move backward over a balanced expression with <C-M-b>

Editing

  • Indent sexp with <C-M-q>
  • Undo with <C-x> u
  • Kill a word with <M-DEL> (DEL seems to be backspace in cygwin)
  • Forward delete word with <M-d>
  • Forward delete word with <M-d>
  • Kill next character with <C-d>
  • Kill till end of line with <C-k>
  • Kill whole line with <C-k>
  • Paste from the system clipboard with <S-Ins> (seems to be cygwin in general)
  • Autocomplete key is <M-/> (just keep hitting it)
  • Kill whitespace until next word is <M-\>
  • Autoindent on the new line with <C-j> (instead of Enter and Tab)
  • Kill balanced expression forward with <C-M-k>
  • Toggle selected region comment with M-;
  • Join current line to the line above with <M-^>
  • Join current line to the line below with <C-u><M-^>

Copy and pasting (marking)

Need to select marking the region first with <C-space>, then move to the other end of the region. Other shortcuts. You can also mark with <C-@>, if <C-space> is used by something enough (e.g. language input toggle on MacOS)

  • Cut text with <C-w>
  • Copy (yank) text with <M-w>
  • Paste from system clipboard with <C-y>
  • <M-h> selects a paragraph
  • Select an sexp with <C-M-h>

Shell

Runs the standard shell is.

Open with <M-x> shell

  • <M-p> to recall previous command
  • <M-r> to reverse search

Macros

From EmacsWiki:

  • <C-x> ( to start defining a macro
  • <C-x> ) to stop defining a macro
  • <C-x> e to execute defined macro
  • <C-u> 10 <C-x> e to execute defined macro 10 times (prefix command)

Misc commands

List minor modes

  • <M-:> evaluates an elisp s-expression
  • <C-c> capitalises the first character of a word
  • <M-X> executes extended command (e.g. eval-buffer)
  • <C-[> can be pressed instead of the Meta key (useful for <M-TAB> - Source)

  • Open up help with <C-h> m (shows minor modes as well) (describe-mode)

  • Show specific keybinding with <C-h> k
  • Show all keybindings available in the buffer <C-h> b

Scheme integration

  • Run scheme interpreter with <M-x> run-scheme
  • Load a scheme buffer into the running guile process with <C-c> <C-l>
  • Evaluate S-expressions into the running Guile process by placing the cursor at the end of the parenthesis, then <C-x> <C-e> (make sure the buffer you're doing this in is in Scheme mode first with <M-x> scheme-mode)

Slime

User Manual

  • <C-x><C-e> evaluates expression before cursor into echo area
  • <C-c><C-d>h looks up the keyword of the cursor

Geiser

  • Cheatsheet
  • Start it up with <M-x> run-geiser <RET> guile
  • Enable geiser minor mode on a buffer with <M-x> geiser-mode, or <C-c><C-z> for it to guess
  • <C-c> <C-s> sets the Scheme implementation if necessary (e.g. can be used to switch from Chicken to Racket)
  • <C-c> <C-d> <C-d> sees the documentation for symbol at point
  • <C-c> <M-e> to jump to REPL after evaluation (in case it fails)
  • <M-x>geiser-restart-repl to restart the repl

Editing

  • <C-c><C-e><C-[> toggles between surrounding square or regular brackets

Documentation

  • Between the parens

  • <C-c><C-d>a to toggle autodocumentation

  • <C-c><C-d><C-d> asks for further information on idenitifer
  • <C-c><C-d>i opens up the manual automatically

Sexp Evaluation

  • <C-u> <C-x> <C-e> evaluates the sexp before point, places result into buffer. Only mentioned off-hand in the official docs, and seems to be inspired by SLIME.
  • <C-c> <C-b> evaluates the buffer
  • <C-c> <C-m> <C-e> macro expands a region

Paredit

Tree editing keybindings

Traversal

  • <C-M-f> goes to next s-expression (if none available, ascends to outer s-expression)
  • <C-M-b> goes to previous s-expression

  • <C-M-d> descends into the next s-expression

  • <C-M-p> descends into the previous s-expression

  • <C-M-u> ascends out of current s-expression on the left

  • <C-M-n> ascends out of current s-expression on the right

Editing

  • <C-)> forward 'slurps' (pulls in next s-expression into current s-expression, e.g. (a b │) c(a b │c))
  • <C-}> backward 'barfs' (spits out s-expression that cursor is on out of enclosing s-expression, e.g. (a b c|)(a b) c│
  • <M-s> gets rid of surrounding parenthesis, e.g. (a b c│)a b c│
  • <C-M-t> transposes sexps. With cursor on the end of a form, you can move it down

Spacemacs

Emacs distribution with custom integrations to make it more vi-like

Not really using this anymore. Remove by deleting all of /.emacs.d

Orgmode

Code blocks

Looks like:

#+begin_src emacs-lisp
(+ 3 4)
#+end_src
  • Use <C-'> to edit the code in a new buffer
  • Use <s to generate the #+BEGIN_SRC snippet (use TAB to complete)

Archiving

Can move subtrees in to a separate archive file to stop it contributing to the agenda (Source)

  • <C-c $> to archive to org-archive-location

Outlines

  • Tabbing on a headline toggles folding
  • Add a 'cookie' to the parent entry of the checkbox list with [/] or [%]
  • <S-←> and <S-→> cycles through workflow states
  • <M-RET> inserts a new heading/item at same level as the one at point
  • <C-u> <C-c> <C-c> to convert add a checkbox to list item
  • <C-c> <C-c> to tick/untick a checkbox
  • <C-c> <C-q> to set a tag
  • <C-c> ' to edit a code block. <C-x> <C-s> to save, <C-c> ' again to exit
  • <C-c> <C-t> to turn entry into a todo entry
  • <C-S-↓> and <C-S-↑> to move an entry up/down
  • <C-c><C-x>\ to toggle utf-8 display, after inputting special/greek symbols

Orgmode can autohide links for readability. (Source)

Format is [[link][description]].

  • <C-c><C-o> to open link in external browser
  • <C-c><C-l> expands link and description for editing

Images

Images and Tables

Can do images like so:

#+CAPTION: This is the caption for the next figure link (or table)
[[./img/a.jpg]]
  • Toggle displaying inline images with <C-c><C-x><C-v>

Motion

From the docs:

  • <C-c> <C-n> next heading
  • <C-c> <C-p> previous heading

Structured:

  • <C-c> <C-f> next heading same level
  • <C-c> <C-b> previous heading same level

  • <C-c> <C-u> up a level heading

Agenda

  • <C-c> a opens agenda
  • <C-c> [ adds current document to agendas
  • <C-c> ] removes current document from agendas
  • <C-'> to go to next buffer in the agenda list
  • <C-c> a m to see a global list of tags from all agenda files (http://orgmode.org/manual/Tag-searches.html#Tag-searches)
  • <C-c> a < to restrict agenda commands to the current buffer

Agenda buffer

  • <C-c> a to bring up agenda
  • f and b to move forward and back weeks in Agenda view
  • w for week view
  • t for fortnight view
  • m for month view
  • q to quit

Magit

Git integration in Emacs

  • <C-x> g to open up, after putting the appropriate keybindings in init.el:
(global-set-key (kbd "C-x g") 'magit-status)

Resources

Magit status

  • s to stage/start tracking a file
  • S to stage all hunks
  • c to prepare to commit (can stage stuff along the way as well)
  • p to prepare to push
  • F does a git pull
  • k to revert changes to an unstaged file
  • zz git stashes
  • zp git stash pops
  • <TAB> on a modified file to see changes

  • <C-u> <C-c> . adds a datetime entry

  • <C-c> . adds a date entry

Glossary

  • Minibuffer: Where Emacs reads complicated arguments, command names, Lisp expressions. By default, uses the echo area for prompts etc. <M-x> commands are minibuffer commands