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 dOpen the.spacemacsfileM-m f e RApply the changed made to.spacemacsM-x <mode>Apply another editing modeM-x package-installInstall 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 variabledotspacemacs-configuration-layersin the.spacemacsfile).
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-packagestoused-but-keep-unusedwhich will prevent Spacemacs from removing the packages you installed manually.
- use the variable
M-x customize-variableCustomize environmental variables for installed packages.
Basic editing
SPC t E eEnable holy-mode (Emacs editing style).M-m t E eDisable holy-mode and enable Vim editing style.M-m t E hDisable holy-mode and enable hybrid-mode.C-/UndoC-?RedoC-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-regionComment the selected region.M-x uncomment-regionUncomment 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 tabifyReplace indent spaces with tabs.M-x untabifyReplace 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.
- Install via
M-x package-install multiple-cursors. - Add
multiple-cursorstodotspacemacs-additional-packagesin your.spacemacsfile. - 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 todotspacemacs/user-configin your.spacemacsfile: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) - Set the environmental variable
mc/always-run-for-allto non-nil.
You can do this viaM-x customize-variable.
See the Github repo for more information.
- Install via
C-S-c C-S-c(mc/edit-lines) Add a cursor to each line in the active region.Sstands for theShiftkey on keyboard.C->(mc/mark-next-like-this)C-<(mc/mark-previous-like-this)C-c C-<(mc/mark-all-like-this)C-jInsert a newline at each of the cursors.C-gQuit multiple-cursors-mode.
Searching
- Type
C-s <keyword>to start a search for - (Optional) Type
M-cto set the case-sensitive flag. - Type
C-sagain, 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>(orC-g) to terminate the search. - Backward search: use
C-rinstead ofC-s. Everything that we have said aboutC-salso applies toC-r, except that the direction of the search is reversed. - Type
Alt %to do query-replace, thenyto confirm the replacement at each occurrence,nto skip,!to confirm without asking, andC-gto 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 oMove the cursor to the other window (“o” for “others”).C-M-vScroll the bottom window.M-m 0Move 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.
