Skip to content

Instantly share code, notes, and snippets.

@becckitt
Last active August 12, 2016 18:20
Show Gist options
  • Save becckitt/858792aaf8f73d6c60425ce2ccf5fd26 to your computer and use it in GitHub Desktop.
Save becckitt/858792aaf8f73d6c60425ce2ccf5fd26 to your computer and use it in GitHub Desktop.
Spacemacs Cheatsheet

#Spacemacs (Vim mode) Cheatsheet (adapted from: https://simpletutorials.com/c/3016/Spacemacs%20Cheatsheet)

###Introduction For project searching, create an empty file named .projectile in your project root directory. For text searching, install AG (the silver searcher) and create an .agignore file to avoid searching certain directories. When searching for files or text in Spacemacs, you can use ctrl-j to go down, ctrl-k to go up, and page up/down.

This sheet assumes you’re using the VIM mode of Spacemacs. When you open a file, you will be in the command mode of the editor. The command mode is not an edit mode; it's just for typing commands. Insertion mode is where you can type text normally (e.g. like in Microsoft Word).

To get into insertion mode, type i (abbreviation for insert) or a (insert after the cursor). To get back into command mode, press the Esc key or rapidly press f d.

If you're ever not sure which mode you're in, just press the Esc key to get into command mode (cursor should change color depending on the mode you're in. In the native theme, command mode is orange, edit mode is green). The below commands are executed in command mode.

###EDITOR Quit SPACE q q

Increase/decrease font size SPACE z x

###CUSTOMIZE Edit the .spacemacs config file SPACE f e d

###FILES Create a file SPACE f f <type in the new file path, press enter, it will ask to create a file (y to create new buffer)>

Open a file globally SPACE f f (then ctrl h to go up a directory, TAB for completion, arrow back to remove level)

Open/Find a file w/in project SPACE p f

Open a recently-opened file SPACE b b

Save file SPACE f s

Open file tree for current file SPACE f t

Open file tree for project root SPACE p t

###FIND Find text in buffer / (type search text, press ENTER, followed by n or N (next/previous))

Find next instance of a word that your cursor is over *

Find previous instance of a word that your cursor is over #

Turn off previous search highlighting :nohl (then press ENTER)

Find text in project SPACE /

Find text under cursor in project (or selected with visual-mode) SPACE *

Resume last search SPACE s l

Find and replace text in buffer, from current line :.,$s///gc

###NAVIGATING ######By character: Go left h

Go down j

Go up k

Go right l

By page:

Go down a page ctrl d

Go up a page ctrl u

######By paragraph: Go up to next paragraph (whitepace line) {

Go down to next paragraph (whitepace line) }

######By special character: Go to previous function [[

Go to next function ]]

Go up to outer brace [{

Go down to outer brace ]}

By word:

Go left a word b

Go right a word w

Go to the end of a word e

Go right 5 words 5w

Jump to any word SPACE SPACE

By file:

Go to beginning of file gg

Go to end of file G

By line:

Go 22 lines down 22j

Go to end of line $

Go to beginning of non-whitespace part of line ^

Undoing navigation:

Jump back ctrl o

Go to the last place you edited g ;

Create/jump to a named bookmark SPACE h b

By cursor position:

Center the buffer around your cursor z z

Go to the file path under your cursor g f

####WINDOW LAYOUTS Split window vertically SPACE w S

Switch to other window SPACE

Close a file without losing buffers SPACE b d

Close a window SPACE w c

Show/hide layout help SPACE l ? (make sure to close the help before creating or saving layouts)

Create a named layout SPACE l l

Save a layout by name SPACE l S

Switch to layout SPACE l

Highlight Text with Visual Mode

Press v. (To enter visual mode so you can highlight text).

Use the arrow keys (or h,j,k,l,w,b,$) to highlight.

Show navigation tree sidebar SPACE f t

Create a new window to the right SPACE w /

Create a new window to the bottom SPACE w -

Restore windows SPACE w u

###DELETING Delete highlighted text d

Delete character x

Delete word dw

Delete word and insert text cw

Delete line dd

Delete to end of line d$

Delete until right paren df)

###COPYING Copy highlighted text Press y to yank, p to paste. (shift-p to open up a line above and paste)

Copy a word yw

Copy a line yy

Copy from cursor to end of line y$

Copy & paste highlighted text from a register Type "ay to yank into register a, and "ap to paste.

###COMMENTING Comment out a line g c c (requires the evil-commentary layer)

Comment out highlighted text g c

###EDITING Undo u

Redo ctrl-r

Change everything between quotes c i “ (this also works for parens, single quotes, etc.)

Show previous things you’ve copied (yanked) SPACE r y

Indenting highlighted text Type > or < to indent right or left. (to indent more, type 2> or 3>)

###WHITESPACE Join lines separated by whitespace J

Show whitespace SPACE t w

Convert spaces to tabs SPACE : (then type tabify and press ENTER)

Convert tabs to spaces SPACE : (then type untabify and press ENTER)

###MAGIT

Check status SPACE g s

Stage a file(in status) s (while cursor is on file)/ u to unstage, TAB to toggle changes

See diff of current file SPACE g d

Git blame SPACE g b (b to blame further, q to quit)

Commit (in commit dialog) C-c C-c (ctrl c, twice. Use empty message to abort.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment