Spacemacs Keybindings

I've used emacs for more than a decade, I really loved it, however recently I find the emacs pinky finger problem gets more serious. Since now I am out of job, it is just the right time to give spacemacs a try. I believe that tools are tools, not for fancy show-casing, so I just use Practicalli's spacemacs configuration instead tweaking my own.

Use mirrors in China

For users in China, use a mirror for spacemacs, this will save a lot time downloading packages. Locate configuration-layer-elpa-archives in ~/.spacemacs.d/init.el and edit as follows:

(setq configuration-layer-elpa-archives
      '(("melpa-cn" . "")
        ("org-cn"   . "")
        ("gnu-cn"   . "")))

Visual selection

vStart visual selection, then use navigation keys to select region
VStart visual selection by entire line(s)
SPC vStart visual selection starting from current word, then use v / V to widen / narrow search.


General editing

IEdit from start of line
AEdit from end of line
iEdit before current character
aEdit after current character
oEdit by starting a new line below
OEdit by starting a new line above
c wChange current world
4 c wChange 4 words starting from current word
v cChange current character
SPC v cChange current word
SPC v dDelete current word
CChange till the end of current line
DDelete till the end of current line
x pTranspose current character with next
SPC x t cTranspose current character with previous
SPC x t wTranspose current word with previous
SPC x t lTranspose current line with previous
SPC S cSpell check and change current word
z =Spell check and change all occurrences of current word
SPC j =Indent region or buffer
SPC { d }Kill paragraph
C-R "Paste from register in edit mode
M-qWrap line (This is hard wrap, for soft wrap use SPC t j)

Programmer editing

d a bDelete current s-expression
d i bDelete the contents of current s-expression
c a bChange current s-expression
c i bChange the contents of current s-expression
y a bCopy current s-expression
y i bCopy the contents of current s-expression
SPC k tTranspose current s-expression with previous
g c cComment current line
M-;Add comment to the end of line
%Jump to matching brackets
C-ksp-kill-hybird-sexp, kill line respecting pair delimiters. Key biding works in normal modes in some major modes


0Go to start of line
^Go to first non-whitespace character in current line
eEnd of world without trailing white space
wEnd of word with trailing white space
f/Go forward to the first occurrence of /
MGo to middle of buffer
HGo to head of buffer
C-uGo up half a page
C-dGo down half a page
SPC j iList of functions/items in current buffer
g dGoto definition
C-oGo back
C-iGo forward (Reverse of C-o)
g ;Go to position of last edit
m aAdd a named marker a
aGo to mark a`
' aGo to the line with mark a
:marksList all marks
''Go to last place
SPC j jJump by character
SPC j lJump by line
C-yscroll down without moving cursor
C-eScroll up without moving cursor
z tPut current line to top of buffer
z bPut current line to bottom of buffer
z zPut current line to center of buffer
8 GGo to line by number
z cFold current block
z oUnfold/Expand current block
SPC t lToggle line wrap, similar to soft wrap seen in other editors
SPC t n vToggle line numbers


Narrowing is very useful to many occasions, e.g., limiting search/replace region, or focusing on function or block.

SPC n fNarrow to function/block
SPC n rNarrow to select region
SPC n wWiden, use this to undo narrowing

Toggle Themes

You can edit themes by editing the values of dotspacemacs-themes in spacemacs configuration file (SPC f e d), when emacs starts it will use the first theme as default theme. A list of themes can be found at emacs-theme-gallery and Spacemacs ThemesSpacemacs Themes. My current favorite dark theme is cyberpunk.

SPC T nSwitch to next theme and open themes transition state, use n/p to preview next/previous theme.

Multi edit

Evil multi-cursor (evil-mc) mode

Use visual selection to select world(s), then use C-p or C-n to select occurrences above or below, then

  • enter edit mode to edit multiple occurrences, or
    • use g r q to quit multi-edit mode, or
    • use g r p or g r n to exclude previous or next occurrence


SPC s eEdit all occurrence of the word under cursor. Spacemacs will display the number of occurrences in the status bar. Use ESC to quit.

Kill ring

SPC r yShow kill ring (helm-show-kill-ring), i.e., list of copy/paste history

Magit, git

SPC g sShow git status
sAdd the highlighted file to staging
c cCreate a commit, edit commit message. Use , , to submit commit or use , k to cancel the commit.
qClose magit window


SPC f fFind file, use C-h to go to parent directory
SPC p fFind file in current project
SPC p kKill project
SPC f e dOpen spacemacs configuration file
SPC f e RReload spacemacs configuration file


treemacs is for viewing and navigating project files.

SPC f tOpen treemacs buffer. Type ? for more key bindings.
SPC p tOpen project root in treemacs buffer
C-c C-p dRemove a project from treemacs buffer
SPC 0If in file buffer, switch to treemacs buffer


ranger is a file manager in emacs.

SPC a t r rOpen ranger buffer
hGo to parent directory
lJump to selected item
y yCopy file
p pPaste file
fSearch by file name


SPC b bList buffers for current layout. (See the remarks below.)
SPC b BList buffers for all layouts. (See the remarks below.)
SPC b .Start buffer transition state. You can then use n, p etc to switch to other buffers b.
SPC TABToggle buffer
SPC b dKill this buffer
SPC b nGo to next buffer
SPC b pGo to previous buffer
SPC b sGo to scratch buffer
SPC b YCopy current buffer
SPC f cSave current buffer as a new file
SPC b wToggle buffer as read-only
SPC f sSave current buffer
SPC f SSave all buffers
SPC f RChange file name of current buffer
SPC f y nCopy file name of current buffer
SPC b uReopen last killed buffer
SPC b C-dKill other buffers


Use M-SPC to enter helm transition state, then you can mark buffer(s) use t and kill the marked buffer(s) with M-D.


Layout is also known as perspective in spacemacs, a layout contains a list of buffers. When spaceemacs is started, the default layout is Global

SPC l lList all layouts
SPC l sSave current layout to a file
SPC l LLoad layout from file
SPC l xKill current layout with all buffers


It's an easy way to pause and resume editing a file. The bookmark- feature is like a light version of layout.

C-x r mbookmark-setCreate a named bookmark
C-x r bbookmark-jumpOpen a saved bookmark


SPC s sSearch with helm-swoop in current buffer
SPC s SSearch with helm-swoop in current buffer for current word
SPC s pSearch with helm-swoop in current project
SPC r lResume last search (helm-resume)
SPC s lRepeat last search (for project search only)
SPC p %Regex replace in all file in project, type ? for help
*Search forward for the word under cursor. Use n or p to go to next or previous match. You can also start iedit from here.
#Search backward for the word under cursor. Use n or p to go to next or previous match. You can also start iedit from here.
SPC s cClear search highlights

If you have ripgrep installed, you can use ripgrep arguments as the search pattern. Example patterns for search the term bql in different files:

  • Search only in Java files:
    -g*.java bql
    //  Or use `-t` flag:
    -tjava bql
  • Search in any files except Java files:
    -g!*.java bql
  • Show 2 lines above and below the occurrence, this works in project search only:
    -C2 bql

Search and replace

After doing search and helm buffered displayed, press C-c C-e, you can then edit the results in a new buffer as if it's a new file, e.g., you can use SPC s e to replace all occurrences.

Undo tree

SPC a uShow undo tree. Use j, k, h, l to select from the edit history.

Spacemacs Clojure mode key bindings

, 'Run Clojure REPL (sesman-start)
, e fEvaluate current s-expression and show result
, s fSend current s-expression to REPL and evaluate
, e vEvaluate expression before point (cider-eval-sexp-at-point)
, e lEvaluate expression at current line
, s bReload current buffer (cider-load-buffer)
, e bEvaluate current buffer
, s aToggle between REPL and Clojure source code
, s nChange REPL namespace to current buffer
, s lClear REPL
, m q qQuit REPL
, m q rRestart REPL (sesman-restart)
, h hShow doc
, e ;Evaluate current s-expression and print result as comment in a new line
, e wEvaluate last s-expression and replace the expression with the result
, e p fEvaluate current s-expression and pretty-print result in a new buffer
, e bEvaluate all code in buffer
, t aRun all tests
, m bBrowse active REPLs (sesman-browse)
, e eEvaluate expression before cursor
, e wEvaluate expression and replace by the results
, e mMacro-expand for immediate macro
, e MMacro-expand for all nested macros
, T eToggle enlighten mode with cider inspector
, d vInspect current symbol
, h acider-apropos, show list of Clojure symbols

Use SPC v followed by v or V to expand or shrink expression selection.

When in Clojure REPL buffer, the following keybinding are available:

C-jCycle up through history
C-kCycle down through history
,Open mini buffer showing cider commands. For instance, you can use clear command to clear REPL buffer.

List state

Lisp State is for easy navigating and editing s-expressions in Clojure mode.

SPC k .Toggle list-state. When lisp-state is on, the status mode indicator is shown as L.

Key bindings in lisp state:

For a complete list of key bindings, see lisp-state

  • Lisp state uses a different set of keybindings, to switch back to normal state, press the ESC key.
    • After calling a Lisp state function, the buffer enters Lisp state, lisp state functions can be triggered without the SPC k prefix.

SPC k .Start lisp state
LNext expression
HPrevious expression
SPC k wWrap expression with parenthesis
SPC k WUnwrap expression
SPC k yCopy expression
SPC k yCopy expression
SPC k sForward slurp expression (move inside the expression after the current s-expression )
SPC k d xDelete s-expression
M-tTranspose current s-expression with previous


To use an existing snippets,

  1. Type the keyword defined in the snippet
  2. Use M-/ to expand with snippet
  3. Use TAB to jump to other makers in the snippet

Sinppets are saved in ~/.spacemacs.d/snippets/ or ~/.emacs.d/private/snippets/ directories.

List of snippets can be found with the yas-visit-snippet-file command.

Every snippet is a single file under a directory named with its target major mode.

A example snippet at ~/.spacemacs.d/snippets/org-mode/journal-entry is shown below, you type journal-entry to trigger the snippet and everything below # -- will be inserted in place for you.

Note: $0 indicates the end cursor position, while $1, $2 etc indicates the initial and second positions.

# -*- mode: snippet -*-
#name : journal-entry
#key : journal-entry
#contributor : jr0cket
# --
* 201912$1
** Thoughts for today
** Code commits
*** .
** Activities in detail
*** .

Zoom / Adjust font size

SPC z fShow mini buffer to adjust font size

Org mode

SPC a o o nList all agenda and todos
g rIn org-agenda buffer, refresh agenda
C-c [org-agenda-file-to-front, add this file to agenda list
tToggle ToDo state selector
, b dCreate a code block
, d dCreate deadline for the current task
, d sSchedule the start date for the current task
, i bCreate a template block, it's more general than , b d
, T cToggle check box (a check box is simply a pair of brackets: [ ])
M-LeftPromote headings
M-RightDemote headings
M-S-LeftPromote headings with all its sub-items
M-S-RightDemote headings with all its sub-items
, i lInsert a link
, i LInsert a link, auto extract link title from the link
SPC a o lStore a link target (org-store-link), use , i l to insert the link
, d dAdd deadline/schedule a task
, s Aorg-archive-subtree, move current node to the archive file
, C porg-pomodoro
, s SSort subtree
C-c @org-mark-subtree, select subtree
C-c C-x C-corg-columns view, press q to quit column view
SPC a o C iorg-clock-in
SPC a o C oorg-clock-out
SPC a o C gorg-clock-goto, goto the active task

If you have source code in an org file, it can be slow to open this file caused by source code evaluation. Disable code eval by adding this header argument: #+PROPERTY: header-args :eval no. See source.

Journal mode

SPC a o j jCreate a new journal for current day
, pPrevious journal
, nNext journal

EasyPG Assistant

You can encrypt or decrypt files with epa- commands, some are listed below.

epa-list-keyList all GPG keys
epa-encrypt-fileEncrypt a file with GPG key. Use symmetric encryption if no key is selected.
epa-decrypt-fileDecrypt a file. Emacs will cache password so you may not be asked to enter password for the file encrypted a short time ago.


Macro in emacs means a sequence of actions usually edits. You can use macro to simplify repetitive tasks.

To define and use a macro:

  1. Press q q to start macro definition, all actions afterwards will be recorded.
  2. Preform the editing actions you'd like to record.
  3. Press q to complete the macro definition.
  4. Press C-x e to execute this macro.
  5. Press e to repeat this macro.
  6. Press ESC to quit macro execution.

If you'd like to execute this macro multiple times, you can always use the number prefix trick. For example pressing 5 C-x e will execute the macro 5 times.


SPC p tShow project tree. Press the enter key to open the file. SPC 0 to go back to project tree. Press q to quit project tree
SPC p aToggle between source code and test file

Window management

The emacs window can be split in to multiple windows.

Press SPC w and some common window-related commands will be displayed in the mini-buffer.

SPC w .Enter window-transition-state, where you can select/move/resize windows
SPC w dDelete current window
SPC w /Split window horizontally
SPC w VSplit window horizontally and focus the new window
SPC w [Resize current window
SPC w sSplit window vertically
SPC w SSplit window vertically and focus the new window
SPC t gToggle window size golden ratio

Toggle Emacs keybindings

You can use C-z to toggle between the default Evil mode and Emacs mode.

Flycheck errors

SPC e nGo to next error
SPC e pGo to previous error
SPC e LGo to flycheck error list


, x xFlutter run or hot reload
, g rFind references


, qrust-quick-run
, = =rust-format-buffer


Install necessary dependencies:

pip install python-language-server
pip install importmagic epc


, ,prview in emacs