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
fileM-m f e R
Apply the changed made to.spacemacs
M-x <mode>
Apply another editing modeM-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 variabledotspacemacs-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
toused-but-keep-unused
which will prevent Spacemacs from removing the packages you installed manually.
- use the variable
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-/
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-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.
- Install via
M-x package-install multiple-cursors
. - Add
multiple-cursors
todotspacemacs-additional-packages
in your.spacemacs
file. - 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-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) - Set the environmental variable
mc/always-run-for-all
to 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.S
stands for theShift
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>
(orC-g
) to terminate the search. - Backward search: use
C-r
instead ofC-s
. Everything that we have said aboutC-s
also applies toC-r
, except that the direction of the search is reversed. - Type
Alt %
to do query-replace, theny
to confirm the replacement at each occurrence,n
to skip,!
to confirm without asking, andC-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.