Spacemacs Holy Cheat Sheet

Spacemacs Holy Cheat Sheet

Spacemacs is an Emacs configuration framework that is known for “mimicking” the behavior of Vim. Since it’s mainly designed for Vim users, nearly all the tutorials and even the official documentation of Spacemacs only cover the Evil mode (Vim editing style).

In this article, I have gathered some of the most useful Spacemacs key bindings in the Holy mode (Emacs editing style). If you are just looking for a decent Emacs distro, Doom Emacs (disable the (evil +everywhere) module) should be the way to go.

Configuration

  • M-m f e d Open the .spacemacs file
  • M-m f e R Apply the changed made to .spacemacs
  • M-x <mode> Apply another editing mode
  • M-x package-install Install Emacs packages.
    By default Spacemacs will keep only the packages that you use (i.e. the packages belonging to a layer explicitly listed in the variable dotspacemacs-configuration-layers in the .spacemacs file).
    To install packages that does not belong to any Spacemacs layers, you can:
    • use the variable dotspacemacs-additional-packages.
    • or create a configuration layer configuring the package and add this layer to dotspacemacs-configuration-layers. See the quick start guide for more info.
    • or set the variable dotspacemacs-install-packages to used-but-keep-unused which will prevent Spacemacs from removing the packages you installed manually.
  • M-x customize-variable Customize environmental variables for installed packages.

Basic editing

  • SPC t E e Enable holy-mode (Emacs editing style).
  • M-m t E e Disable holy-mode and enable Vim editing style.
  • M-m t E h Disable holy-mode and enable hybrid-mode.
  • C-/ Undo
  • C-? Redo
  • C-k (kill-line) Kill rest of line or one or more lines.
  • M-k (kill-sentence) Kill to the end of the sentence.
  • C-w (kill-region) Kill the highlighted region.
  • M-w (kill-ring-save) Copy the region into the kill ring.
  • C-x C-; (comment-line) Comment/uncomment the current line.
  • M-; (comment-dwim) Add comment to the end of current line.
  • M-x comment-region Comment the selected region.
  • M-x uncomment-region Uncomment the selected region.
  • M-m t w (whitespace) Show/Hide whitespace.
  • C-x h (mark-whole-buffer) Put the whole document in selection.
  • M-x tabify Replace indent spaces with tabs.
  • M-x untabify Replace tab with spaces.
  • M-m t h a (spacemacs/toggle-automatic-symbol-highlight) Enable/Disable automatic symbol highlight.
  • M-m t f (fill-column-indicator) Enable/Disable fill-column indicator.

Multiple Cursors

  • (Prerequisite) Install and configure the multiple-cursors package.
    1. Install via M-x package-install multiple-cursors.
    2. Add multiple-cursors to dotspacemacs-additional-packages in your .spacemacs file.
    3. Multiple cursors does not do well when you invoke its commands with M-x.
      It needs to be bound to keys to work properly.
      You can for example add the following snippet to dotspacemacs/user-config in your .spacemacs file:
      1
      2
      3
      4
      (global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
      (global-set-key (kbd "C->") 'mc/mark-next-like-this)
      (global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
      (global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
    4. Set the environmental variable mc/always-run-for-all to non-nil.
      You can do this via M-x customize-variable.
      See the Github repo for more information.
  • C-S-c C-S-c (mc/edit-lines) Add a cursor to each line in the active region.
    S stands for the Shift key on keyboard.
  • C-> (mc/mark-next-like-this)
  • C-< (mc/mark-previous-like-this)
  • C-c C-< (mc/mark-all-like-this)
  • C-j Insert a newline at each of the cursors.
  • C-g Quit multiple-cursors-mode.

Searching

  • Type C-s <keyword> to start a search for
  • (Optional) Type M-c to set the case-sensitive flag.
  • Type C-s again, to search for the next occurrence of
  • Type <DEL> to go back to an earlier location of the . If there are no earlier occurrences, the <DEL> erases the last character in the search string.
  • Type <Return> (or C-g) to terminate the search.
  • Backward search: use C-r instead of C-s. Everything that we have said about C-s also applies to C-r, except that the direction of the search is reversed.
  • Type Alt % to do query-replace, then y to confirm the replacement at each occurrence, n to skip, ! to confirm without asking, and C-g to cancel the search.

Multiple Windows

  • C-x 0 (delete-window)
  • C-x 1 (maximize-buffer)
  • C-x 2 (split-window-below)
  • C-x 3 (split-window-right)
  • C-x o Move the cursor to the other window (“o” for “others”).
  • C-M-v Scroll the bottom window.
  • M-m 0 Move the cursor to window 0,… (0 is the NeoTree window).
  • C-x 4 f (find-file-other-window)
  • C-x 5 f (find-file-other-frame)
  • C-x 5 2 (make-frame-command)

Project commands

  • M-m p p (helm-projectile-switch-project) Retrieve the list of projects, or in other words, the local git repositories that Spacemacs remembers you as having edited.
  • M-m p f (helm-project-find-file) Find files in the current project.
  • M-m p t (neotree-find-project-root) List project files in a new window positioned on the left.

Buffer

  • M-m TAB (last buffer) Switch to last buffer in the current window (switch back and forth).
  • M-m b b (helm-mini) Switch to a buffer using helm.
  • M-m b d (kill-this-buffer) Kill the current buffer (does not delete the visited file).
  • M-m b e (safe-erase-buffer) Erase the content of the buffer (ask for confirmation).
  • M-m b h (home) Open spacemacs home buffer.

Git

  • M-m g s (magit-status) Show Magit status view.

Comments