From Vim to Spacemacs...?
Table of Contents
A few days ago I decided to try out Spacemacs, an Emacs Kit designed around Evil Mode (vi simulation in Emacs) and a Leader key (Space, hence Spacemacs). The Spacemacs tagline says “the best editor is neither Emacs nor Vim, it’s Emacs and Vim!”: let’s see how it feels!
What I want from my editor #
- vi motions :)
- git integration
- customization
- file navigation and manipulation
- seamless navigation between the editor’s splits and
tmux
panes - editing of lisp s-expressions
What I got with Spacemacs #
First of all, a great documentation! In general, a tool already packed with a number of nice-to-have
features and a consistent set of keybindings (more about this below).
First impressions #
“Oh god, it’s so slow!”
I soon got through that stage by having a Emacs server running in the background (emacs --daemon
) and connecting to it with emacsclient .
!
A note about keybindings #
All keybindings are organized around <Space>
followed by a sequence of keys and they are grouped by functionality, so (for example) all git
related keybindings are prefixed by <Space> g
. This makes it much easier to remember them, and gives a very consistent experience! If you don’t remember a specific binding but you still remember its prefix, you can type the prefix and wait, a popup will show you all the defined keybindings… Also, <Space> ?
will bring up a popup which allows you to search through all the keybindings.
Vi motions #
Spacemacs is built around Evil Mode, an amazing simulation layer which gives all the vi
motions I can think of. One small (intended) difference between standard vi
motions and Spacemacs is in how s
behaves in visual mode: it has been in fact remapped to some sort of vim-surround
functionality… Here’s an example: say we have the word hello
and we select it (ve
), then we press s
… Nothing happens because Spacemacs is still waiting for an input. If we now type "
we get "hello"
. I’m still getting used to this but I like to have this easy way to surround a selection! Also, the original functionality is still available by using c
.
Update: Unlike previously stated in this post, it is actually possible (and very easy) to use jk
as the escape sequence but there was a mistake in my configuration. As suggested by @spacemacs
(thank you, this tip made my day!), it can be set by adding the following expression to dotspacemacs/init
(setq evil-escape-key-sequence "jk")
Git integration #
The git
configuration layer provides a nice git integration (although git gutter
is a bit buggy). Tip: time machine
(<Space> g t
) allows you to browse through the current file’s git history!
Customization #
Out of the box, Spacemacs already provides some nice-to-have
s (find file in project, surround words, easy motion): in addition, there are many configuration layers
to choose from, so most of the times one line in .spacemacs
is enough!… and of course, there’s elisp
!
File navigation #
Integration with projectile
is packed under the prefix <Space> p
, which provides features well known to CtrlP
users like myself: for example, <Space> p f
brings up a popup which lets your search a file everywhere in the project (projects
are defined implicitly: the root is the directory which contains a .git
repository) whereas <Space> p e
brings up a list of recently opened files.
Seamless navigation between emacs and tmux #
It’s as easy as adding one line to .spacemacs
(the tmux
configuration layer) and define the keybindings in tmux.conf
. Done! The keybindings are available here: evil-tmux-navigator.
Editing of lisp s-expressions #
I’m not a lisp
ninja but I like to write some clojure
code every now and then, and I grew used to paredit.vim
, which happens to be a porting of Emacs own paredit
to vim
… Spacemacs uses evil-lisp-state to provide the same functionality, available under the prefix <Space> k
.
Conclusions (for now) #
So far I’m pretty happy about Spacemacs, also considering that setting it up to have a configuration very close to my vim
’s took me just a couple of hours (mostly spent reading the documentation). This gave me enough motivation to try and make the switch: since yesterday, vim
is aliased to emacsclient
in my shell… Let’s see how this goes!