Skip to content

Instantly share code, notes, and snippets.

@loverde
Forked from davoclavo/spacemacs-cheatsheet.md
Last active December 7, 2018 21:00
Show Gist options
  • Save loverde/dac8bb9b16d62905d948ae10f34c7e7f to your computer and use it in GitHub Desktop.
Save loverde/dac8bb9b16d62905d948ae10f34c7e7f to your computer and use it in GitHub Desktop.
Spacemacs cheatsheet

emacs --daemon to run in the background. emacsclient.emacs24 <filename/dirname> to open in terminal

NOTE: "M-m and SPC can be used interchangeably".

  • Undo - C-/
  • Redo - C-?
  • Change case: 1. Camel Case : M-c 2. Upper Case : M-u 3. Lower Case : M-l
  • Helm-projectile find file : M-m p f
  • Helm-projectile-grep : M-m p s g
  • Toggle Auto complete : M-m t a
  • Neotree root directory : M-m p t
  • Linum-relative : M-m t r
  • Ace-jump mode : M-m SPC *. Helm-bookmarks : M-m h b
  • Iedit mode : 1. M-<left>, M-<right> to navigate, 2. C-; to select/deselct all for edit at once
  • Expand Region 1. Expand: M-m v 2. Contract: M-m V
  • Winner mode: 1. Undo : C-c <left> 2. Redo : C-c <right>
  • Toggle Aggressive Indent Mode : M-m t I
  • Open file in new buffer after M-m p f : C-c o
  • Dired mode : 1. Copy file : C 2. Delete the file : D 3. Rename the file : R 4. Create a new directory : + 5. Reload directory listing : g
  • Search : 1. The last searched query : C-s C-s 2. The string under the cursor : C-s C-w
  • Un-indent by 4 spaces : C-u -4 C-x TAB
  • Open emacs dired mode: M-m a d
  • Erase contents of buffer: M-m b e
  • Replace contents of buffer with the contents of the clipboard: M-m b P
  • Copy contents of the whole buffer: M-m b Y
  • Open current file directory: M-m f j
  • Rename current file: M-m f R
  • Indent region/buffer: M-m j =
  • Kill all buffers (of current project): M-m p k
  • Reload spacemacs conf: M-m f e R
  • Kill all buffers except the current one: M-m b K
  • Go to conf file (~/.spacemacs): M-m f e d
  • Toggle display fill-column(column 80): M-m t f
  • Enable/Disable read-only mode C-x C-q
  • Go one level up in directory: C-x C-j
  • Indent/unindent region by n/-n spaces(n=4,8,... usually): C-u <n> C-x TAB
  • Go to previous cursor position(before ace-jump): `M-m SPC ``
  • Do ag (code search) inside project : M-m s a p
  • Narrow to function : M-m n f (M-m n w to exit)
  • Enable rainbow mode: M-m t C c
  • Search selected region or current word through ag in project: M-m s p
  • Highlight search results in another buffer (helm swoop): M-m s s (M-m s s to exit)
  • Toggle current frame transparency: M-m T T
  • Toggle non-matching lines for iedit mode: C-' when in iedit mode (C-;)
  • Helm-resume background task: M-m h l
  • Enter .spacemacs diff mode: M-m f e D
  • Show kill ring history: M-m r y
  • When in dired mode, press ? to display a list of commands.
  • Search within given buffer (helm-swoop mode): M-m s s
  • List all functions in the given buffer (imenu): M-m s l

Useful Spacemacs commands

  • SPC q q - quit
  • SPC w / - split window vertically
  • SPC w - - split window horizontally
  • SPC 1 - switch to window 1
  • SPC 2 - switch to window 2
  • SPC w c - delete current window
  • SPC TAB - switch to previous buffer
  • SPC b b - switch buffers
  • SPC f f - find a file
  • SPC f s - save a file (:w also works)
  • SPC p p - open project
  • SPC p h - find a file in current project
  • SPC b d - kill current buffer
  • SPC b M - move buffer to another window
  • SPC v - enter expand-region mode
  • SPC b b - Helm mini; lists buffers & recent files
    • CTRL SPC - Mark Items
    • CTRL z - Actions
  • SPC b B - ibuffer
  • SPC f f - open files
    • CTRL h - up a folder
    • CTRL l - open a folder
    • CTRL j - up
    • CTRL k - down
  • SPC p f - opens root of project
  • SPC p p - opens projects
  • SPC / - searches through project
  • SPC s s - search in a file
  • SPC s l - find all function definitons in a file
  • SPC v - expand region
  • SPC V - contract region
  • s ( - put parens around a region
  • SPC s e - multiple cursors
    • n - jump
    • N - jump
  • SPC h d - help describe
  • SPC h d f - help describe functions
  • SPC h d v - help describe variables
  • SPC f e h - help
  • ALT / - snippet completion
  • SPC t s - syntax checking
  • SPC e - syntax checking options
  • SPC a r - ranger
  • SPC a d - deer

unimpaired

  • [e - Move line up
  • ]e - Move line down
  • [SPACE - Insert space above
  • ]SPACE - Insert space below
  • [p - Paste above current line
  • ]p - Paste below current line

evil-mc

  • grm - make-all-cursors
  • gru - undo-all-cursors
  • grs - pause-cursors
  • grr - resume-cursors
  • grf - make-and-goto-first-cursor
  • grl - make-and-goto-last-cursor
  • grh - make-cursor-here
  • M-n - make-and-goto-next-cursor
  • grN - skip-and-goto-next-cursor
  • M-p - make-and-goto-prev-cursor
  • grP - skip-and-goto-prev-cursor
  • C-n - make-and-goto-next-match
  • grn - skip-and-goto-next-match
  • C-t - skip-and-goto-next-match
  • C-p - make-and-goto-prev-match
  • grp - skip-and-goto-prev-match

Eyebrowse

  • gt - go to next workspace
  • gT - go to previous workspace
  • SPC l w n - create or switch to workspace n
  • SPC l w TAB - switch to last active workspace
  • SPC l w c - close current workspace
  • SPC l w n or SPC l w l - switch to next workspace
  • SPC l w N or SPC l w p or SPC l w h - switch to previous workspace
  • SPC l w r - set a tag to the current workspace
  • SPC l w w - switched to tagged workspace

Find/Replace

  • Alt % - query-replace; active region, or cursor point to end interactive find/replace
    • y - do the replacement.
    • n - skip
    • ! - do this and all remaining replacements without asking.
    • Ctrl+g - cancel.

Git

SPC g b open a magit blame SPC g B quit magit blame SPC g c commit changes SPC g C checkout branches SPC g d show diff prompt SPC g D show diff against current head SPC g e show ediff comparison SPC g E show ediff against current head SPC g f show fetch prompt SPC g F show pull prompt SPC g H c clear highlights SPC g H h highlight regions by age of commits SPC g H t highlight regions by last updated time SPC g i git init a given directory SPC g I open helm-gitignore SPC g l open a magit log SPC g L display the log for a file SPC g P show push prompt SPC g s open a magit status window SPC g S stage current file SPC g m display the last commit message of the current line SPC g t launch the git time machine SPC g U unstage current file Highlight by age of commit or last update time is provided by smeargle. Git time machine is provided by git-timemachine. Git last commit message per line is provided by git-messenger. 3.1 Magit

Spacemacs uses magit to manage Git repositories.

To open a status buffer, type in a buffer of a Git repository: SPC g s

Spacemacs uses evil-magit for key bindings in magit buffers (unless your editing style is set to emacs, in which case you get the default magit bindings), which are the standard magit key bindings with some minimal changes to make them comfortable for evil users.

Here are the often used bindings inside a status buffer:

Key Binding Description / evil-search $ open command output buffer c c open a commit message buffer b b checkout a branch b c create a branch f f fetch changes F (r) u pull tracked branch and rebase gr refresh j goto next magit section C-j next visual line k goto previous magit section C-k previous visual line l l open log buffer n next search occurrence N previous search occurrence o revert item at point P u push to tracked branch P m push to matching branch (e.g., upstream/develop to origin/develop) q quit s on a file or hunk in a diff: stage the file or hunk x discard changes

  • on a hunk: increase hunk size
  • on a hunk: decrease hunk size S stage all TAB on a file: expand/collapse diff u on a staged file: unstage U unstage all staged files v or V select multiple lines z z stash changes 3.2 Staging lines

Magit allows you to stage specific lines by selecting them in a diff and hitting s to stage. Due to inconsistencies between Vim and Emacs editing styles, if you enter visual line state with V, you will stage one more line than intended. To work around this, you can use v instead (since Magit only stages whole lines, in any case).

3.3 Commit message editing buffer

In a commit message buffer press ,c (if dotspacemacs-major-mode-leader-key is ,) or C-c C-c to commit the changes with the entered message. Pressing ,a or C-c C-k will discard the commit message.

Key Binding Description h go left j go down k go up l go right 3.4 Interactive rebase buffer

Key Binding Description c or p pick e edit f fixup j go down gj move line down k go up gk move line up d or x kill line r reword s squash u undo y insert ! execute 3.5 Quick guide for recurring use cases in Magit

Amend a commit: l l to open log buffer c a on the commit you want to amend ,c or C-c C-c to submit the changes Squash last commit: l l to open log buffer r e on the second to last commit, it opens the rebase buffer j to put point on last commit s to squash it ,c or C-c C-c to continue to the commit message buffer ,c or C-c C-c again when you have finished to edit the commit message Force push a squashed commit: in the status buffer you should see the new commit unpushed and the old commit unpulled P -f P for force a push (beware usually it is not recommended to rewrite the history of a public repository, but if you are sure that you are the only one to work on a repository it is ok - i.e. in your fork). Add upstream remote (the parent repository you have forked): M to open the remote popup a to add a remote, type the name (i.e. upstream) and the URL Pull changes from upstream (the parent repository you have forked) and push: F -r C-u F and choose upstream or the name you gave to it P P to push the commit to origin 3.6 Git-Flow

magit-gitflow provides git-flow commands in its own magit menu.

Key Binding Description % open magit-gitflow menu 3.7 Git time machine

git-timemachine allows to quickly browse the commits of the current buffer.

Key Binding Description SPC g t start git timemachine and initiate micro-state c show current commit n show next commit N show previous commit p show previous commit q leave micro-state and git timemachine Y copy current commit hash

Useful Vim key bindings

movement

  • 0 - beginning of line
  • ^ - beginning of non-whitespace
  • $ - end of line
  • 9j - move down 9 lines
  • w - move forward by word
  • b - move backward by word
  • gg - first line
  • G - last line
  • C-u - up half page
  • C-d - down half page
  • f/ - move forward to first "/" character
  • t/ - move forward right before the first "/" character
  • ; - repeat that command again
  • H - head of the screen
  • M - middle of the screen
  • L - last of the screen
  • } - move forward by paragraph or block
  • { - move backwards by paragraph or block
  • * - search for word under the cursor
  • n - search again forward
  • N - search again backwards
  • # - search backwards for word under cursor
  • / - search forward
  • ? - search backward
  • % - find matching brace, paren, etc
  • ma - mark a line in a file with marker "a"
  • ``a` - after moving around, go back to the exact position of marker "a"
  • 'a - after moving around, go back to line of marker "a"
  • :marks - view all the marks
  • '' - go to the last place you were

editing

  • x - delete char under cursor
  • X - delete char before cursor
  • A - add to end of line
  • I - insert at the beginning of the line
  • dd - delete line
  • D - delete from cursor to end of line
  • di' - delete text inside single quotes
  • yy - copy line
  • Y - copy from cursor to end of line
  • cc - change line
  • C - change from cursor to end of line
  • cit - change text inside html tag
  • ci' - change text inside single quotes
  • ci{ - change text inside curly brackets.
  • ci... - etc
  • p - paste after cursor
  • P - paste before cursor
  • o - add line below
  • O - add line above
  • . = repeat last comment
  • r - replace character
  • R - replace. (overwrite) (good for columns of text)
  • J - join line (cursor can be anywhere on line)

visual mode

  • v - visual char mode
  • V - visual line mode
  • C-v - block visual mode
SPC s c remove highlight

**** Files manipulations key bindings
Files manipulation commands (start with ~f~):

| Key Binding | Description                                                    |
|-------------+----------------------------------------------------------------|
| ~SPC f c~   | copy current file to a different location                      |
| ~SPC f C d~ | convert file from unix to dos encoding                         |
| ~SPC f C u~ | convert file from dos to unix encoding                         |
| ~SPC f D~   | delete a file and the associated buffer (ask for confirmation) |
| ~SPC f E~   | open a file with elevated privileges (sudo edit)               |
| ~SPC f f~   | open file with =helm= (or =ido=)                               |
| ~SPC f F~   | try to open the file under point =helm=                        |
| ~SPC f j~   | jump to the current buffer file in dired                       |
| ~SPC f l~   | open file literally in =fundamental mode=                      |
| ~SPC f L~   | Locate a file (using =locate=)                                 |
| ~SPC f o~   | open a file using the default external program                 |
| ~SPC f R~   | rename the current file                                        |
| ~SPC f s~   | save a file                                                    |
| ~SPC f S~   | save all files                                                 |
| ~SPC f r~   | open a recent file with =helm=                                 |
| ~SPC f t~   | toggle file tree side bar using [[https://github.com/jaypei/emacs-neotree][NeoTree]]                        |
| ~SPC f v d~ | add a directory variable                                       |
| ~SPC f v f~ | add a local variable to the current file                       |
| ~SPC f v p~ | add a local variable to the first line of the current file     |
| ~SPC f y~   | show current file absolute path in the minibuffer              |

**** Emacs and Spacemacs files
Convenient key bindings are located under the prefix ~SPC f e~ to quickly
navigate between =Emacs= and Spacemacs specific files.

| Key Binding | Description                                                        |
|-------------+--------------------------------------------------------------------|
| ~SPC f e c~ | open =ido= in the =contrib= folder                                 |
| ~SPC f e d~ | open the spacemacs dotfile (=~/.spacemacs=)                        |
| ~SPC f e D~ | open =ediff= buffer of =~/.spacemacs= and =.spacemacs.template=    |
| ~SPC f e f~ | discover the =FAQ= using =helm=                                    |
| ~SPC f e i~ | open the all mighty =init.el=                                      |
| ~SPC f e R~ | resync the dotfile with spacemacs                                  |
| ~SPC f e v~ | display and copy the spacemacs version                             |


--
## Comment
SPC ;	comment operator
SPC c y	comment and yank
SPC c p	comment paragraphs

--
## Find files
SPC ff: find files or url
SPC pf: find file in project
SPC ph: search in a project with helm
SPC bb: search in buffers

--
## Search in files
SPC ss
/: search with evil

--
## Window
SPC w =	balance split windows
SPC w c	close a window
SPC w c	close a window
SPC w C	delete another window using ace-delete-window
SPC w d	toggle window dedication (dedicated window cannot be reused by a mode)
SPC w [hjkl] move to window
SPC w [HJKL] move the window
SPC w s or SPC w -	horizontal split
SPC w S	horizontal split and focus new window
SPC w u	undo window layout (used to effectively undo a closed window)
SPC w U	redo window layout
SPC w v or SPC w /	vertical split
SPC w V	vertical split and focus new window
SPC w w	cycle and focus between windows
SPC w m	maximize/minimize a window (maximize is equivalent to delete other windows)
SPC w M	maximize/minimize a window, when maximized the buffer is centered

--
## buffer
SPC TAB	switch to alternate buffer in the current window (switch back and forth)
SPC b b	switch to a buffer using helm
SPC b d	kill the current buffer (does not delete the visited file)
SPC b e	erase the content of the buffer (ask for confirmation)
SPC b h	open *spacemacs* home buffer
SPC b k	kill a buffer
SPC b K	kill all buffers except the current one

--
## Project
=projectile= commands start with p:

| Key Binding | Description                                           |
|-------------+-------------------------------------------------------|
| ~SPC p !~   | run shell command in root                             |
| ~SPC p &~   | run async shell command in root                       |
| ~SPC p a~   | toggle between implementation and test                |
| ~SPC p b~   | switch to project buffer                              |
| ~SPC p c~   | compile project using =projectile=                    |
| ~SPC p d~   | find directory                                        |
| ~SPC p D~   | open project root in =dired=                          |
| ~SPC p f~   | find file                                             |
| ~SPC p G~   | regenerate the project's =etags= / =gtags=            |
| ~SPC p h~   | find file using =helm=                                |
| ~SPC p I~   | invalidate the projectile cache                       |
| ~SPC p k~   | kill all project buffers                              |
| ~SPC p o~   | run =multi-occur=                                     |
| ~SPC p p~   | switch project                                        |
| ~SPC p r~   | open a recent file                                    |
| ~SPC p R~   | replace a string                                      |
| ~SPC p s~   | see [[Searching in a project][search in project]]                                 |
| ~SPC p t~   | open =NeoTree= in =projectile= root                   |
| ~SPC p T~   | find test files                                       |
| ~SPC p v~   | open project root in =vc-dir= or =magit=              |
| ~SPC p y~   | find tags                                             |
| ~SPC /~     | search in project with the best search tool available |
| ~SPC s a p~ | run =ag=                                              |
| ~SPC s g p~ | run =grep=                                            |
| ~SPC s k p~ | run =ack=                                             |
| ~SPC s t p~ | run =pt=                                              |

--
## errors
SPC e n	go to the next error
SPC e p	go to the previous error

--
## Quit
SPC q q	Quit Emacs and kill the server, prompt for changed buffers to save
SPC q Q	Quit Emacs and kill the server, lose all unsaved changes.
SPC q r	Restart both Emacs and the server, prompting to save any changed buffers
SPC q s	Save the buffers, quit Emacs and kill the server
SPC q z	Kill the current frame
--
## Ruby on rails

| Key binding   | Description                                                     |
|---------------+-----------------------------------------------------------------|
| ~SPC m r f a~ | find localization file                                          |
| ~SPC m r f c~ | find controller                                                 |
| ~SPC m r f e~ | find environment file                                           |
| ~SPC m r f f~ | find feature                                                    |
| ~SPC m r f h~ | find helper                                                     |
| ~SPC m r f i~ | find initializer                                                |
| ~SPC m r f j~ | find javascript file                                            |
| ~SPC m r f l~ | find library                                                    |
| ~SPC m r f m~ | find model                                                      |
| ~SPC m r f n~ | find migration                                                  |
| ~SPC m r f o~ | find log                                                        |
| ~SPC m r f p~ | find spec file                                                  |
| ~SPC m r f r~ | find rake task                                                  |
| ~SPC m r f s~ | find stylesheet file                                            |
| ~SPC m r f t~ | find test                                                       |
| ~SPC m r f u~ | find fixture                                                    |
| ~SPC m r f v~ | find view                                                       |
| ~SPC m r f y~ | find layout                                                     |
| ~SPC m r f @~ | find mailer                                                     |
| ~SPC m r g c~ | go to current controller                                        |
| ~SPC m r g d~ | go to DB schema                                                 |
| ~SPC m r g e~ | go to DB seeds                                                  |
| ~SPC m r g h~ | go to current helper                                            |
| ~SPC m r g j~ | go to current javascript                                        |
| ~SPC m r g g~ | go to Gemfile                                                   |
| ~SPC m r g m~ | go to current model                                             |
| ~SPC m r g n~ | go to current migration                                         |
| ~SPC m r g p~ | go to current spec                                              |
| ~SPC m r g r~ | go to routes                                                    |
| ~SPC m r g s~ | go to current stylesheet                                        |
| ~SPC m r g t~ | go to current test                                              |
| ~SPC m r g u~ | go to current fixture                                           |
| ~SPC m r g v~ | go to current view                                              |
| ~SPC m r g z~ | go to spec helper                                               |
| ~SPC m r g .~ | go to file at point (faster but less powerful than ~SPC m g g~) |

** Refactoring

| Key binding   | Description                 |
|---------------+-----------------------------|
| ~SPC m r R x~ | extract region into partial |

** RUN commands

| Key binding   | Description          |
|---------------+----------------------|
| ~SPC m r :~   | run rake task        |
| ~SPC m r c c~ | run rails generator  |
| ~SPC m r i~   | start rails console  |
| ~SPC m r s r~ | reload Rails project |
| ~SPC m r x s~ | start rails server   |

** Ex-commands

| Key binding | Description                             |
|-------------+-----------------------------------------|
| ~:A~        | Switch between implementation and tests |

--

# Ruby

* Key bindings
** Ruby (enh-ruby-mode, robe, inf-ruby, ruby-tools)

| Key binding | Description                                          |
|-------------+------------------------------------------------------|
| ~SPC m '~   | toggle quotes of current string (only built-in mode) |
| ~SPC m {~   | toggle style of current block (only built-in mode)   |
| ~SPC m g g~ | go to definition (robe-jump)                         |
| ~SPC m h d~ | go to Documentation                                  |
| ~SPC m s f~ | send function definition                             |
| ~SPC m s F~ | send function definition and switch to REPL          |
| ~SPC m s i~ | start REPL                                           |
| ~SPC m s r~ | send region                                          |
| ~SPC m s R~ | send region and switch to REPL                       |
| ~SPC m s s~ | switch to REPL                                       |
| ~SPC m x '~ | Change symbol or " string to '                       |
| ~SPC m x "~ | Change symbol or ' string to "                       |
| ~SPC m x :~ | Change string to symbol                              |
| ~%~         | [[https://github.com/redguardtoo/evil-matchit][evil-matchit]] jumps between blocks                    |

** RuboCop

| Key binding   | Description                                          |
|---------------+------------------------------------------------------|
| ~SPC m r r f~ | Runs RuboCop on the currently visited file           |
| ~SPC m r r F~ | Runs auto-correct on the currently visited file      |
| ~SPC m r r d~ | Prompts from a directory on which to run RuboCop     |
| ~SPC m r r D~ | Prompts for a directory on which to run auto-correct |
| ~SPC m r r p~ | Runs RuboCop on the entire project                   |
| ~SPC m r r P~ | Runs auto-correct on the project                     |

** Tests
*** RSpec-mode
When =ruby-test-runner= equals =rspec=.

| Key binding | Description                                   |
|-------------+-----------------------------------------------|
| ~SPC m t a~ | run all specs                                 |
| ~SPC m t b~ | run current spec file                         |
| ~SPC m t c~ | run the current spec file and subsequent ones |
| ~SPC m t e~ | mark example as pending                       |
| ~SPC m t f~ | run method                                    |
| ~SPC m t l~ | run last failed spec                          |
| ~SPC m t m~ | run specs related to the current buffer       |
| ~SPC m t r~ | re-run last spec                              |
| ~SPC m t t~ | run spec at pointer                           |

*** Ruby-test-mode
When =ruby-test-runner= equals =ruby-test=.

| Key binding | Description         |
|-------------+---------------------|
| ~SPC m t b~ | run test file       |
| ~SPC m t t~ | run test at pointer |


Git commands (start with ~g~):

| Key Binding | Description                                         |
|-------------+-----------------------------------------------------|
| ~SPC g b~   | open a =magit= blame                                |
| ~SPC g B~   | quit =magit= blame                                  |
| ~SPC g c~   | commit changes                                      |
| ~SPC g C~   | checkout branches                                   |
| ~SPC g d~   | show diff prompt                                    |
| ~SPC g D~   | show diff against current head                      |
| ~SPC g e~   | show ediff comparison                               |
| ~SPC g E~   | show ediff against current head                     |
| ~SPC g f~   | show fetch prompt                                   |
| ~SPC g F~   | show pull prompt                                    |
| ~SPC g H c~ | clear highlights                                    |
| ~SPC g H h~ | highlight regions by age of commits                 |
| ~SPC g H t~ | highlight regions by last updated time              |
| ~SPC g i~   | git init a given directory                          |
| ~SPC g I~   | open =helm-gitignore=                               |
| ~SPC g l~   | open a =magit= log                                  |
| ~SPC g L~   | display the log for a file                          |
| ~SPC g P~   | show push prompt                                    |
| ~SPC g s~   | open a =magit= status window                        |
| ~SPC g S~   | stage current file                                  |
| ~SPC g m~   | display the last commit message of the current line |
| ~SPC g t~   | launch the git time machine                         |
| ~SPC g U~   | unstage current file                                |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment