Spacemacs Basics

Explanation of some Spacemacs basics by GreyGhostIX

GreyGhostIX on Reddit did such a great job of explaining some Spacemacs basics that I thought I should copy it verbatim here:

There is a lot of help at your fingertips if you dont know how to do something. Hit space and just browse your options, or use spc h to see a lot of help options. Some helpful bindings to explore are :

  • spc h T(Help Tutor): open vim-tutor. You may not need to do this if you have done vimtutor before.
  • spc h d k(Help Describe Key): describe what a vim style key is bound to do. For example, if you forgot what ; does, try this command followed by that key.
  • spc ?: lets you search for keybindings. Enter runs the function.
  • spc h d f(Help Describe Function): search for a function, enter to describes it.
  • spc spc(Helm M-x): search for a function, enter to run it.
  • ,(major mode leader): this is the same as spc m, and gives you access to all the bindings that are specific to your major mode that may not fit into the default categories.

Functions

Function refers to the thing that you are calling when you hit a key or series of keys. For example j in normal modeis mapped to the function evil-next-line. In elisp these usually look like strings of hyphenated words. spc spc opens helm M-x and lets you search for functions by name and execute them. Note that functions may also be refered to as sexps (symbolic expressions).

Buffers

Buffers are like tabs in your browser. You open them from files on your computer instead of from the internet, and they stay open until you close them. Hit spc b b to see a searchable list of your open buffers, and recently opened buffers. spc b B opens a list of buffers organized by major mode. spc b d deletes the buffer you are currently in. As you can most the spc b commands are related to buffers. But buffers arent necessarily just files you open, they can also be generated by emacs (like the helm mini buffer (spc b b) you use to search buffers) to do useful things.

The Mode Line

At the bottom of the window, you will see the mode line. Its got some handy information in it. From left to right it shows you:

  • Your window number. The color indicates what evil mode you are in (normal, insert, etc)
  • A little * indicator if your file has been modified since it has been saved.
  • Buffer size.
  • Buffer name (same as file name if you have opened from file).
  • Major mode.
  • Minor modes.

On the far right is info about where you are in a buffer. Move around whth hjkl and watch it if you dont get it at first.

Major Modes

This is how emacs organizes important sets of functionality. Each buffer will have one major mode at a time. It can customize anything about emacs so that it suits the buffer you are working with. There is a mode for editing C#, a mode for editing latex, a mode for viewing files (dired-mode), a mode for searching (helm-major-mode), a mode for emulating a terminal (term-mode). You can see what major mode you are in at the bottom of each buffer in your mode line. Usually this is automatically set depending on which buffer you are in. Major modes specific functions are on the , key (also spc m).

Minor Modes

Minor modes are smaller sets of custom behavior that can work together. A major mode will automatically set a bunch of relevant minor modes, but you can toggle them with spc t. For example spc t n toggles a minor mode for line numbers. You can hover over the symbols in the modeline with your mouse to see what minor mode each represents. spc h d m (help describe mode) opens a comprehensive list of your active minor modes. Move your cursor to one and hit enter to get more information.

Side Note: The information opens in a split buffer titled *help*. Many of these buffers that are meant to be temporary can be closed quickly with q.

Layers

Everything so far (except specific key bindings) applies to emacs in general. Layers, however, are a spacemacs specific term. Layers are meant to be a simple way for you to customize your configuration by adding only one line to your .spacemacs file. See the list to see what are available. Check out the latex layer for example.

The .spacemacs file

Hit spc f e d (file emacs dotfile) to open this file. This is where you can customize everything. Find the dotspacemacs-configuration-layers line. You can use / in normal mode to start searching for it and enter when you have it. Add latex in that list. It should look like this:

dotspacemacs-configuration-layers ‘(

latex

other-layer

other-layer)

Now spacemacs will load that layer on startup for you, which includes a major mode for editing latex and a bunch of commands. You can now either restart emacs, or hit spc f e R(file emacs reload) to reload your config. Now if you hit spc f f (file find) and open a latex file you should have some syntax highlighting and latex specific commands on your , key.