How to love Spacemacs ❤️

Ronie Uliana
3 min readApr 25, 2020

Spacemacs has what we love from VI, but with batteries included and with sane defaults.

Silhouette of person in the middle of a heart shape firework at night
Love is in the… space

The idea here is to show some concepts to help understand why a lot of people like Spacemacs and VI editing style. Then give you some helpful commands to play with.

So, here are the two concepts to understand why we ❤️ Spacemacs:

  • Write in short bursts. We spend most of the time moving around and copying/deleting/changing text. When we write, we do it in short bursts and then go back to navigation and edition.
  • Operate it as an instrument. The commands are composable, so we play them like chords on a piano (that’s poetic, isn’t it?!)

Write in short bursts

Different from other editors, Spacemacs expects us to spend most of our time moving things around and navigating. So the normal state is that any letter we type is considered to be a command.

The basic example is: how do we add text?

  1. Type “i” meaning you want to insert text;
  2. Write something;
  3. Hit ESC, meaning you’ve finished writing.

Think of ESC as “I’ve finished writing.” Every time we type ESC, we return to the normal state of navigating and moving things around.

My guess is that it’s the root cause of confusion for people coming from other editors. On them, writing is the default and commands are an “exception.” In Spacemacs, commands are the default and writing is just another command.

Play it like an instrument

Commands are composable in Spacemacs.

That means we type a sequence of letters to do what we want. It looks like playing a (very simple) piano. Sometimes we play the wrong chord, and we have to do it again. But more often than not, we use a chord so much that we do it unconsciously.

For example, in the text below to change the word “examples” for “tests,” we put the cursor anywhere in the word “examples”…

I’ve seen some exam|ples.

Then we type ciwtests<esc> and it becomes:

I’ve seen some tests.

Here is the command decomposed:

  • “c” — change
  • “iw” — a word
  • “tests” — the replacement text
  • <ESC> — finish writing

Another example. Let’s say we want to remove the content of parenthesis, put the cursor anywhere inside or over the parenthesis…

if (a == 1)

Then type di), the parentheses inner stuff is deleted (don’t forget to type the parenthesis after di, the full command is di).

if ()

Decomposing the command:

  • “d” — delete
  • “i)” — inside parentheses (yeah, that’s “i” followed by “closing parenthesis”)

There is no need to press <ESC> there because we didn’t write anything.

With those two examples, I bet you can figure out the commands for “change inside parentheses” and “delete a word”.

Here a list of commands to experiment:

  • “d” — delete
  • “c” — change
  • “v” — select
  • “y” — copy (called “yank” in VI, don’t ask me why…)

Here’s an incomplete list of things to use with commands, they are called text objects in Spacemacs terminology:

  • “iw” — a word, no spaces included
  • “aw” — a word, posterior space included (useful command daw)
  • “i]” — inside brackets
  • “a]” — brackets and it’s content
  • “il” — a line, but not the starting indentation
  • “al” — a line from beginning to end
  • “ii” — all lines with the same indentation
  • … and so on

And, to finish, a small list of commands that don’t need an argument:

  • “u” — undo. We use it a lot, every time we type the wrong chord.
  • “.” — repeat the last chord (second most useful command ever after undo)
  • “p” — paste after the cursor.
  • “P” — Paste before the cursor (that’s SHIFT+p)

A few extra threads to follow!

Navigating around the text is probably the most common thing we do, so Spacemacs has a bunch of single-letter commands to do it. It ranges from small movements like moving to the next word (“w”), or to the previous one (“b”), until some really complex ones like “gd” (go to definition), or “SPACE j j” (this one is crazy!).

You may also want to try “macros”. They allow you to record any complex sequence of commands and replay it at will.

Both topics are too long for me to add here, but each one alone would make Spacemacs be worth of trying.

--

--