Spacemacs: Windows, Buffers and Quitting!

This is the Chapter 2 of a Series of Blog Posts about Spacemacs, feel free to check out the starting point on Vim and Emacs: Spacemacs! or use the following links to go to the previous or the next chapter in the series:

<<< Browse and Save Files on SpacemacsCustomize Spacemacs >>>

Today we’re going to talk about Windows! (And the other things in the title)

“I’ve reviewed your code” she said, holding the Test Suite results. (by voltamax)

Basic Window Control

  • Wanna start a new vertical window on the right? SPC w / or SPC w v

(As a nice Vim support, :vsplit or :vs will work just fine).

This will keep the focus on the current window. But if you want to start a vertical window on the right and move the focus: SPC w V will do it.

  • Wanna start a new horizontal window below? SPC w or SPC w s

(As a nice Vim support, :split or :sp will work just fine).

This will keep the focus on the current window. But if you want to start an horizontal window below and move the focus: SPC w S will do it.

Those are nice mnemonics (and I will address that on the next blog post) because SPC is the m-x key in Spacemacs (got it? m + x = Em X or Emacs) then you add the w (as in “window”) and a slash for vertical or dash for horizontal. C’mon, it’s nice.

Killing Windows and Switching to another Window

You can kill the focused window (filled cursor) using SPC w d.

If you have two windows (that is, the screen is splitted either horizontally or vertically) you can kill the unfocused window using SPC w D.

After you have one or more windows open, you can switch to the first one by pressing SPC 1 (note the absence of w). Likewise, SPC 2 will take you to the second window and so on.

Another way to switch focus between windows is by going “to the right/left” or “up/down”:

  • SPC w l: To the left.
  • SPC w h: To the right.
  • SPC w k: Upwards.
  • SPC w j: Downwards.

All the above commands will also work to go the “minibuffer”, but it also has its own shortcut: SPC w b.

HELM Find Files running on the minibuffer. On this case on the bottom of the screen, accessible by SPC + w + b.

It’s very common for me to work alternating between two files… obviously there’s a a̶p̶p̶ shortcut for that: SPC tab will switch the buffer in the current window.

Basic Buffer Usage

Project navigation can be really straightforward using language specific Packages and Layers. But it is also nice to know how to switch to an already opened file, using the buffer list:

SPC b b: Opens the buffer list and allows a fuzzy search by file name.

If you use the arrow key to go sufficiently down, you can reach recent files, not on opened buffers.

And, among the opened buffers you can see the “Messages” buffers that may present important debugging messages from Spacemacs itself (like startup problems) and other packages (like git conflicts).

Whenever you feel like “cleaning up” the buffers, enter one of them (by pressing Enter/Return on the SPC b b) and press SPC b d to delete the buffer but not the file on disk.

As expected, the Vim command :bdelete or :bd also works here.

Finally, by using SPC b s (love this shortcut), we’re taken to the Scratch buffer, were we can just annotate random code snippets, links and whatever.

Sometimes I feel like “keeping only the buffer on the screen”: SPC b m kills all other buffers, except the one on the focused window.

Exiting Spacemacs

Turns out you can use the :q to exit Spacemacs. But you can also do it by using the Control Q (Windows) or ⌘Q (Mac). Linux anyone?

On the next article I talk about the basics of Spacemacs Customization!

Want to stay up to date? I’m also on GitHub and Twitter (how unexpected!).