How to love Spacemacs ❤️

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
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

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

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!

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.

Written by

Just a common guy

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store