Skip to content

Instantly share code, notes, and snippets.

@danielkrizian
Last active September 24, 2024 17:39
Show Gist options
  • Select an option

  • Save danielkrizian/8c89e0b977932ff75af65e34e7d1bf03 to your computer and use it in GitHub Desktop.

Select an option

Save danielkrizian/8c89e0b977932ff75af65e34e7d1bf03 to your computer and use it in GitHub Desktop.
spacemacs cheatsheet

useful spacemacs commands

  • SPC q q quit
  • C-g abort action
  • SPC w / split window vertically
  • SPC w - split window horizontally
  • SPC w c delete current window
  • SPC f f find a file
  • SPC f s save a file (:w also works)
  • 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 s l find all function definitons in a file
    • n 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
  • M-/ snippet completion
  • SPC t s syntax checking
  • SPC e syntax checking options
  • SPC a r ranger
  • SPC a d deer

motion (cursor)

  • 9j move down 9 lines
  • w b - word forward/backward
  • 0 $ ^ line beginning/end/first-non-whitespace
  • H M L window goto head/middle/last
  • gg G buffer line first/last
  • C-u C-d window half up/down
  • C-b C-f window up/down
  • gg G buffer top/last line
  • ( ) sentence
  • { } paragraph
  • % matching brace, paren, etc
  • f t F T find char forward/one before/backward/one after (enter desired character after this prefix)
    • f/ forward to first “/” character
    • t/ forward right before the first “/” character
  • ; - repeat last find
  • '' last place you were in history

source code (imenu / semantic)

https://www.spacemacs.org/layers/+tools/imenu-list/README.html

  • SPC bi focus imenu tree sidebar (creating if necessary)
  • SPC Ti toggle imenu tree sidebar
  • SPC ji jump in buffer (helm imenu)
  • q quit imenu-list window
  • r refresh imenu-list window
  • d RET display/goto current entry, keep/abandon focus
  • f fold/unfold current section

window

  • SPC 1 switch to window 1
  • SPC 2 switch to window 2

buffer

  • SPC TAB switch to previous buffer
  • SPC b b switch buffers
  • SPC b B ibuffer
  • SPC s s search in a file

project

  • SPC p p open project
  • SPC / searches through project

marks

  • m mark a line in a file with marker char that follows
    • ma - mark a line in a file with marker “a”
  • ` ' go to exact position/line of marker char that follows
    • `a 'a after moving around, go back to the exact-position/line of marker “a”
  • :marks view all marks evil-marks
  • C-SPC C-SPC mark C-u C-SPC go to last mark in the ring , cycles last 16 marks

org subtree (must be under heading 1 or deeper)

  • SPC a o r helm-org-rifle open org buffers
  • helm-org-rifle-directories selected dirs; (with prefix: recursively)
  • helm-org-rifle-files selected files
  • hem-org-rifle-org-directory in org-directory

how to move between minibuffer window focus and back

  • M-m ww other window, followed by M-m wb switch to minibuffer window

search

  1. / ? * # search forwards/backwards/word forwards/word backwards
  2. n N search again forwards/backwards
  3. SPC h c clears highlight

helm

  • C-SPC mark items
  • M-a select all items
  • M-g helm-ff-run* functions
  • C-z actions
  • C-h C-l C-k C-j up/down tree/selection
  • SPC rl resume last helm session
  • SPC a' available repls

visibility

scrolling

SPC N hjklHJKLbfgG transient scroll line/half-page/full-page/buffer

code folding

  • SPC z . transient state for folding code
  • zc zo zm zr fold/open current/all in buffer

show/hide compilation window

  • SPC cd show/hide compilation window

(v)isual selection

  • v or C-v or V - select block/region
  • SPC v expand region
  • SPC V contract region
  • vig select all in buffer
  • viw vaw inner/a word

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)

C-v multi-line editing

  • C-v jjj grI <edit text> grq edit multiple lines at once

iedit : multi-occurence editing

  1. SPC se *e edit all occurences of symbol under cursor
  2. TAB n N occurence toggle/next/previous
  3. f restrict the scope to function
  4. s i x substitute/insert/xterminate
  5. ESC

snippets

  • M-/ - paste template e.g. q M-/ for q source code block in org-mode. powered by yas-hippie-try-expand
  • SPC SPC yas-visit-snippet-file view/edit templates

source code

  • M-; comment indent

selection edit/replace

  • daw caw vaw word under cursor delete/change/visual select; uses evil-a-word
  • M-% - 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.
    • C-g - cancel.
  • SPC se *e iedit state (after you selected region); then s substitute and type desired replacement
  • opening/closing parenthesis means with/without space
  • start with one of y, d, c, v, V, then s then optional i, s, f then any symbol to use as surround
    • vs( put parens around a region
    • vs} surround the selection with curlies
    • cs]{ change surrounding brackets with curlies including space
    • ds{ delete surrounding curlies
    • yss) wrap entire line in parentheses
    • ysiw] wrap word with brackets
    • Vs<p class "important">RET wrap with custom tags
    • vsfmyfunctionRET wrap with myfunction()

evil

unimpaired

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

multiple cursors

https://practicalli.github.io/spacemacs/spacemacs-basics/evil-tools/multiple-cursors.html

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

layouts and workspaces

window arrangement

  • SPC w r SPC w R rotate windows forward/backward

layout : a window configuration with buffer isolation

eyebrowse/workspace

  • 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

git

  • SPC g . version control transient state
  • 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

command line git

http://ndpsoftware.com/git-cheatsheet.html

consolidate many commits into one

git checkout yourBranch
git reset $(git merge-base master yourBranch)
git add -A
git commit -m "one commit on yourBranch"

always git pull -r

git config --global pull.rebase true why use it, or at least git pull -r https://mergebase.com/blog/doing-git-wrong/

smerge SPC g r - (r)esolve merge conflicts

https://develop.spacemacs.org/layers/+source-control/version-control/README.html

  • SPC g r Smerge mode transient state

gist

http://jr0cket.co.uk/2016/03/Using-Github-Gists-from-Spacemacs.html#:~:text=Github%20Gists%20are%20really%20useful,github%20layer%20to%20your%20~%2F.

  • SPC f s save buffer to upload to github.com

SPC g g l

  • RET opens the gist in a new buffer
  • g reload the gist list from server
  • e edit the gist description, so you know what this gist is about
  • k delete current gist
  • b opens the gist in the current web browser
  • y show current gist url & copies it into the clipboard
  • * star gist (stars do not show in gist list, only when browsing them on github)
  • ^ unstar gist
  • f fork gist - create a copy of your gist on gist.github.com
  • + add a file to the current gist, creating an additional snippet on the gist
  • - remove a file from the current gist

gist in Dired

  • m @ mark file, make public gist (private if used with prefix)

magit

  • gr refresh
  • $ open command output buffer
  • c c open a commit message buffer
  • l l open log buffer
  • b b b c branch checkout/create
  • f f fetch changes
  • F (r) u pull tracked branch and rebase
  • P u P m push to branch: tracked/matching (e.g., upstream/develop to origin/develop)
  • j k goto magit section next/prev
  • C-j C-k visual line next/prev
  • / evil-search
  • n N search occurrence next/prev
  • o revert item at point
  • s S stage the file or hunk / stage all
  • x discard changes
  • + - on a hunk: increase/decrease hunk size
  • TAB xpand/collapse diff (on a file)
  • u U unstage staged file / all
  • z z stash changes

recurring use cases

compare two revs/commits
a) d r, START, .., END , RET - use completion with TAB to populate START and END

b) l, mark the start/end commits as region, d d

Stage specific lines
select* them in a diff and hit s to stage (V will stage one more line than intended - use v instead)
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
http://www.howardism.org/Technical/Emacs/magit-squashing.html
  • 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
  • b u set branch.master.remote to upstream
  • F u fetch upstream
  • b b checkout (master) branch
  • m m merge (upstream/master)
  • (old way?) - F -r C-u F and choose upstream or the name you gave to it
  • P P to push the commit to origin
Tag
  • t r then P t

Interactive rebase buffer

  • c or p pick
  • e edit
  • f fixup
  • gj move line down
  • gk move line up
  • d or x kill line
  • r reword
  • s squash
  • u undo
  • y insert
  • ! execute

Git time machine

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

  • SPC g t start git timemachine and initiate micro-state
  • c n N p show current/next/previous/previous commit
  • Y copy current commit hash

files

SPC f f C-c r edit file as root

processes

  • g revert/refresh
  • m d u <backspace> M U mark/unmark at point/all
  • o omit (filter out) marked

SPC a P server processes

https://www.masteringemacs.org/article/displaying-interacting-processes-proced

  • T tree view, showing children and parents
  • F column selection
  • f filter rows
  • RET filter on point
  • t invert marks
  • C P mark children
  • s sort
  • k x send signal (TERM by default)
    • ? review the log after sending signal
    • r renice command

SPC a p emacs processes

tables with org-table

Creating Tables

ShortcutAction
TABCreate a new table or move to the next field
RETMove to the next row

Basic Table Editing

ShortcutAction
M-LEFTMove column left
M-RIGHTMove column right
M-UPMove row up
M-DOWNMove row down
C-c -Insert a horizontal line

Resizing and Alignment

ShortcutAction
C-c TABRealign the table
C-c ^Sort the table

Advanced Features

ShortcutAction
C-c +Sum numbers in a column/region
C-c `Edit field in separate window
C-c }Narrow table to column
C-c {Widen table

Exporting Tables

ShortcutAction
C-c C-cExport table to different format

Notes

  • Table editing in Org-mode is context-sensitive. The shortcuts only work when the cursor is within a table.
  • To add rows or columns, simply move to where you want the new row or column and start typing.
  • Use TAB to cycle through fields and create new rows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment