An Introduction into Spacemacs from a Vim user
Tags: emacs, spacemacs, vim
Published: 2018-11-28 17:16:09

---
title: An Introduction into Spacemacs from a Vim user
published: true
tags: emacs,spacemacs,vim
canonical_url: https://thecode.pub/an-introduction-into-spacemacs-from-a-vim-user-f0d9c860911e
---

![](https://cdn-images-1.medium.com/max/400/0*1WlehGOk0peCQhbx.jpg)

I’m a Vim user. I use it in my workflow all the time, but I enjoy trying other editors sometimes and I will share my experience playing with Spacemacs.

### What is Spacemacs?

Spacemacs is a starter kit for Emacs that makes it easier for anyone to use it. It has the [Evil](https://github.com/emacs-evil/evil) plugin by default. Evil is a layer for Emacs that emulates Vim. I always try vim mode in all other editors and they all are not so good, Evil is one of the best Vim emulators that I’ve already seen. It makes it easier for me to use Emacs, since it emulates Vim commands that I already know.

Spacemacs has easy to remember keybindings. Everything starts with the SPC key (it is like the leader key from Vim) and all belongs to some group. For example: SPC b for all buffers commands and SPC p for all project commands. If you don’t remember the command, press SPC SPC and it brings an autocomplete buffer to search for commands.

### How do I experiment another editor?

It’s hard for me to learn all the stuffs from a tool in a day or two. So when I want to learn more about an editor, I force myself to experiment it for at least one week, trying to do everything on the new editor without opening others. To use an editor I need to learn how to search files, how to navigate through files and how split the window, only this.

### Installation

First, you should install Emacs.  
You can use Homebrew to install emacs on mac:

```
brew install emacs --use-git-head --cocoa --srgb
```

To install on Linux, you can follow this [documentation](https://www.gnu.org/software/emacs/manual/html_node/efaq/Installing-Emacs.html).   
Now you can install the Spacemacs distribution:

```
git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
```

Now open Emacs..

![](https://cdn-images-1.medium.com/max/1024/0*isSOE_FDRGXQ0Yth.png)<figcaption>Spacemacs Startup Screen</figcaption>

### The Basics

Spacemacs has the concept oflayers . The idea is to have a collection of packages with some configurations. The documentation says:

> Layer: A collected unit of configuration that can be enabled (or disabled) in Spacemacs. A layer typically brings together one or more packages, as well as the glue configuration code required to make them play well with each other and Spacemacs in general.

Once you open Emacs, enter SPC f e d, this will take you to Spacemacs configuration file (~/.spacemacs). Here you can add layers inside dotspacemacs-configuration-layers. For example:

```
dotspacemacs-configuration-layers
 '(
 elixir
 (ruby :variables ruby-version-manager 'rvm)
 ruby-on-rails
 )
```

This adds layers for working with Elixir, Ruby and Ruby on Rails

### Navigating through a file

To navigate on the file, I use the Vim commands.

```
gg =\> goes to the top of the file
G =\> goes to the bottom
h =\> left
j =\> down
k =\> up
l =\> right
```

(to learn more about navigation, [read here](http://vim.wikia.com/wiki/Moving_around))

### Loading your project

After loaded, you can use SPC a d (or File -\> Open Directory) to open your project.

![](https://cdn-images-1.medium.com/max/352/1*f2aEVrVO424eAKVfUN8XhA.png)

It will load this buffer and you can find your project file. Hit Enter to load it

Spacemacs includes [Projectile](https://github.com/bbatsov/projectile), an Emacs library for handling projects. So, after you added your project the first time with SPC a d , you can use SPC p p to Switch between projects

![](https://cdn-images-1.medium.com/max/350/1*G6tl43SpJFd1sDuu7EtwyA.png)

### Terminology

I like to use this image to understand Emacs terminology

![](https://cdn-images-1.medium.com/max/1024/0*V790P2DvSbUyLai3.jpg)<figcaption><a href="https://emacs.stackexchange.com/questions/13583/whats-the-difference-between-a-buffer-a-file-a-window-and-a-frame">https://emacs.stackexchange.com/questions/13583/whats-the-difference-between-a-buffer-a-file-a-window-and-a-frame</a></figcaption>

Usually in most applications we call the running instance as window, but on Emacs we call it the Frame . A frame can contain multiple Windows and inside each window we have a Buffer loaded (on the image above, the buffer loaded is indicated by the yellow circle). A buffer can be the content of a loaded file or the output of some command execution. Every time you open a file, it changes the active buffer to this file, but the buffer with the past file opened is still alive. You can use SPC b b to see all buffers and switch them

![](https://cdn-images-1.medium.com/max/1024/1*g6xsZuwBoh-7bLpRhbuD9g.gif)

You can easily switch between the last used buffer with SPC TAB

![](https://cdn-images-1.medium.com/max/1024/1*1OWdL-LXoWbS5C8w5YQoYA.gif)

### Searching for a file

The first thing that I learn in a new editor is: How can I search for a file?

In Spacemacs we can do a fuzzy file search pressing SPC p f

![](https://cdn-images-1.medium.com/max/1024/1*eeEs8GYQu-IJ2pOjUyiXVA.gif)<figcaption>Fuzzy file search</figcaption>

Another way is to search for Classes and methods using Tags. SPC p G will generate a TAGS file for your project. After generated, you can search through tags with SPC p g

![](https://cdn-images-1.medium.com/max/1024/1*AkzXGmwPbIx1mvNkYM0tog.gif)<figcaption>Searching by Class/Method Name using Tags</figcaption>

You can also open a tree explorer using SPC p t

![](https://cdn-images-1.medium.com/max/1024/1*ykdIGDHb5hKUN55v7ptXMA.gif)<figcaption>SPC p t will open the tree explorer</figcaption>

### Splitting window

Another feature that I use a lot is splitting the window. You can use the Emacs keybinding to do it:

```
SPC w - =\> Split window into two windows, one above the other.
SPC w / =\> Split window into two windows, side by side.
```

Or using the vim commands:

```
:sp =\> Split window into two windows, one above the other.
:vsp =\> Split window into two windows, side by side.
```

![](https://cdn-images-1.medium.com/max/1024/1*4HZiedewGWiJNSNhE5I46g.gif)<figcaption>Splitting the window</figcaption>

After splitting, you will notice that a number is defined in the window

![](https://cdn-images-1.medium.com/max/1024/1*K02Mq9n_eMlv8ABamsD8nw.png)

To jump into a window, you can press SPC NUMBER to go to that window (for example, SPC 3 take me to the right window on the image)

![](https://cdn-images-1.medium.com/max/1024/1*qgxRsfzVDJU4dzLYg75m7A.gif)<figcaption>Switching between windows</figcaption>

You can kill a window with SPC w d or :q .

![](https://cdn-images-1.medium.com/max/1024/1*buC_BQKmCPKUoA-6rFKkmA.gif)

Sometimes when working on more than one window in the same frame (for example, having a class and a test file opened together), I like to maximize one of them. You can use SPC w m to maximize and use it again to return it.

![](https://cdn-images-1.medium.com/max/1024/1*bc0ZGbmD9gjSB17zVILoXg.gif)

### My Workflow working with it

Usually, my workflow with Vim involves Tmux too. I typically have 3 Tmux panes open. One for the editor (Vim), another for the terminal (to run tests, ssh, etc), and one for the server (and the logs).

![](https://cdn-images-1.medium.com/max/1024/1*i_-7O6wOGJ_R68ezpzNbzA.gif)<figcaption>My workflow with Vim and tmux</figcaption>

I also like to use [vim-test](https://github.com/janko-m/vim-test) to run my tests inside Vim

![](https://cdn-images-1.medium.com/max/1024/1*mb3axdT9givXhxTqp7lhXA.gif)

Emacs for another side, have the idea that you can do everything on the Emacs itself. You can start your server on it, open a terminal, etc, without having the needing to have multiple terminals for each thing (although I still have they open when working on Emacs 😄)

My next examples use the rails layer on Spacemacs.

I can run bundle install (to install my ruby dependencies) inside it with SPC m b i

![](https://cdn-images-1.medium.com/max/1024/1*xvFEvzNsI5xh6Qunk36dFQ.gif)

I can run the rails server inside it and check the logs:

![](https://cdn-images-1.medium.com/max/1024/1*xek3DjksVemXCqtavhSswg.gif)

and also run the tests directly from Emacs:

![](https://cdn-images-1.medium.com/max/1024/1*vEjoFzZNxuPcZ8ads4H62Q.gif)

Follow a simple mindmap that I created for these basic commands:

![](https://cdn-images-1.medium.com/max/1024/1*VKqD5q2PaAuZj4UZnBZf7A.png)

And this is all the basics that I need to use it and that I want to share.

![](https://cdn-images-1.medium.com/max/1024/1*eqsPaN0ft0DkhHczXD5vJA.png)

Cheers 🍻

* * *