Actually getting Spacemacs to do stuff

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


(Tacking a bunch of stuff on top quickly, to be reorganized later.) Cider displays its own error buffer whenever the REPL throws an error, even though you also get a stacktrace in the repl buffer. This is redundant and obnoxious. To make it stop, put (setq cider-show-error-buffer nil) in your user-config function in .spacemacs.

More tutorials:

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
f d (quickly) escape from basically anything, like obnoxious error message buffers or screwed-up commands
{spc} (wait) "helm" menu pops up, giving you all kinds of commands to explore.
{spc} c l comment line (cap-L to uncomment)

It appears to be called spacemacs for a reason. And the commands are basically organized under namespaces under {spc}

selective file edit and copy into buffer from file commands listed here: https://github.com/syl20bnr/evil-tutor/blob/master/tutor.txt (too much to deal with right now)

Windows

(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: http://vim.wikia.com/wiki/Moving_around

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.

Editing

(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 vim.wikia.com:

  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. Osx GUI seems to give it full access to system clipboard using usual mac keystrokes.

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

Clojure

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.

I'm told that , is an alias for {spc}-m in clojure state.

see also:

https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Blang/clojure

cider docs

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.

Pandoc

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

see also: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Btools/pandoc

Dash

{spc} d d lookup under cursor

{spc} d D lookup at point and specify docset

see also: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Btools/dash

Pending layers

(Haven't started exploring these yet.)

git: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Bsource-control/git

github: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Bsource-control/github

version-control: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Bsource-control/version-control

ess (R): https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Blang/ess

Markdown: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Blang/markdown

ipython notebook: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Blang/ipython-notebook

javascript: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Blang/javascript

html: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Blang/html

geeknote/evernote: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Btools/evernote

python: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Blang/python