Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
everything I've managed to learn so far about spacemacs (gist can't handle pandoc tables, view in raw)

so it turns out pandoc markdown + github + lots of symbols = sadness and chaos. Here's a slightly less ugly version, though still pretty uggo:*

Actually getting Spacemacs to do stuff

(Notes, mostly to self, and based on my own needs. Shared in case others need too.)

Absolute basics

Emacs but with vim keybindings.

"meta" = {M} = alt/option control = {C} = control

emacs -nw opens in terminal rather than gui.

Most commands only work in normal mode, which it starts in.

: commands need to be followed by {enter}, most others do not

"buffer" = file

"state" in emacs = "mode" in vim ("mode" in emacs is roughly "package" in something like sublime) (but modes aka packages are combined in spacemacs into "layers" that play nice together)

Command Function

i enter insert mode ("state") a enter insert state after cursor ("append") {esc} leave insert state, enter normal state :w save ("write") :wqa! save and quit :qa! quit without saving (the ! means no confirm) {spc} f e d open spacemacs config file {spc} t n toggle line numbers {spc} T n rotate color scheme :bd close a buffer :buffers see buffers list :edit F edits filename F {spc} {tab} switch to last buffer :!cmd execute command in shell

selective file edit and copy into buffer from file commands listed here: (too much to deal with right now)


(Source: mostly Clojure for the Brave and True)

I think windows and buffers are independent, i.e., opening and closing windows just makes more or fewer buffers visible, doesn't actually change whether those buffers are open or not.

Command Function

{C}-x 3 Split window to the side {C}-x b Choose a buffer to put in active window {C}-x o Switch cursor to another window {C}-x 0 Close current window {C}-x 1 Close all windows except active {C}-x 2 Split windows above and below

Moving Around

(source: a combination of evil mode tutorial and wikia)

Command Function

h move cursor left l move cursor right k move cursor up j move cursor down G move to end of buffer gg move to beginning of buffer :num move to line num % move to matching paren or other delimiter {C}-f page-down {C}-b page-up e end of word w beginning of word, moving fwd b beginning of word, moving bkwd $ end of line 0 beginning of line ) forward 1 sentence ( backward 1 sentence } forward 1 paragraph { backward 1 paragraph

There are more listed here:

many of the nagivation commands take a prepend number.

Allegedly there's also a bookmark system where mchar sets a mark and `char jumps to it or 'char to beginning of line.

The arrow keys also work, but vimmers may burn one as a heretic. In gui, mouse scroll works too, not in terminal.


(Source: mostly evil mode tutorial)

A number of commands take an argument as second keystroke. That will be indicated by ~* below. Available arguments include:

Arg Means

w cursor to end of word incl space e cursor to end of word w/o space $ cursor to end of line

such commands also take an optional number in front saying how many times to execute

Command Function

x delete character under cursor d~* delete ~* dd delete line u undo {C}-R redo r cha replace character under cursor w/ cha R like r, but keeps going for more chars. c ~* like r, but replace ~* w/ what you type o insert newline below cursor and enter insert state O like o, but for above cursor. These are letter o. A jump to end of line and enter insert state

Copy and Paste

Basic normal mode commands are

y~* for copy

d~* for cut

p for paste after cursor; P for paste before cursor.

(see above re delete, cut and delete are the same thing)

The below steps for using visual mode are copied from

  1. Position the cursor where you want to begin cutting.

  2. Press v to select characters (or uppercase V to select whole lines, or Ctrl-v to select rectangular blocks).

  3. Move the cursor to the end of what you want to cut.

  4. Press d to cut (or y to copy).

  5. Move to where you would like to paste.

  6. Press P to paste before the cursor, or p to paste after.

Copying and pasting goes into internal emacs clipboard, not system clipboard.

Deletions via x, c, and d also land in the emacs clipboard.

From the above, it follows that one can move a line by dd followed by p.

Similarly, one can copy 2 lines by 2yy followed by p to paste.

In addition, iTerm2 is perfectly happy to paste from system clipboard into an emacs buffer using normal mac keystrokes, although I can't get it to copy out of one. Haven't tried with emacs GUI.

Search and Replace

Command Function

:s/o/n replace first occ. on line of o with n :s/o/n/g replace all occurrences on line :#,#s/o/n/g replace all occ. between the two (line) nums :%s/o/n/g replace all occ. in buffer.

Layers I use


Right now, I'm right about to the level of being able to open a repl. {M}-x cider-jack-in does it.

apparently so does {spc} m s i

MAYBE that requires the following in project.clj:

  :repl {:plugins [[cider/cider-nrepl "0.10.0-SNAPSHOT"]
                      [refactor-nrepl "2.0.0-SNAPSHOT"]]
                                :dependencies [[alembic "0.3.2"]
                                                         [org.clojure/tools.nrepl "0.2.12"]]}

Evaluating things

Command Function

{spc} m s n eval NS form in repl {spc} m s f eval function in repl {spc} m s F eval function in repl and switch to repl {spc} m s e eval last sexp in repl

the business with the capitalization about functions is a common pattern -- capitalizing the last letter shoots focus over to the repl and puts you in insert state over there.

evaling a function works from cursor anywhere in the function. evaling ns works from anywhere in buffer. but the eval sexp ones seem very picky about cursor placement. It looks like to evaluate an entire, appropriately nested, sexp, it really needs to be way after the end. Like on the next line.

There are tons of other keybindings too, to be learned over time... it looks like there's lots of cool stuff, e.g., for managing ns requires and such.

honorable mention:

{spc} m f b goes and re-indents the whole buffer for you. Ok cider, I'm cool with that.

see also:

Also see the spacemacs documentation for lisp editing:

That documentation is a little ambiguous, tells you how to enter lisp state with a command, but doesn't say how to enter subsequent commands. Everything starts with:

{spc} k and then a letter for the command

that gets you into lisp state, and then I think you just type the letter while still in lisp state (before {esc}ing out) to execute commands again?

Important lisp state commands: s forward slurp S backward slurp b forward barf B backward barf w wrap expr in parens W unwrap

It seems like in general the key mappings in the modes/layers start with {spc} then a special letter for their mode -- m for clojure, k for lisp, etc.


{spc} P / throws open a menu to pandoc-ify things.

see also:


{spc} d d lookup under cursor

{spc} d D lookup at point and specify docset

see also:

Pending layers

(Haven't started exploring these yet.)




ess (R):


ipython notebook:





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