Spacemacs setup
Table of Contents
1 Spacemacs installation
Install emacs on your platform (apt
on Ubuntu or the distro's app store, brew
on MacOS (update: better to install from https://emacsformacosx.com/ since you'll get proper GUI support), download .exe from https://www.gnu.org/software/emacs/download.html for Windows). Install 32-bit version (at least if you are on Windows) as that seems to have better performance compared to the 64-bit version. I downloaded emacs-26.3-i686.zip
for my Windows machine
Run the following commands:
rm -r ~/.emacs.d (make backup if you already have this folder) git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
At the time of writing (Dec 2019), the released version of spacemacs is 0.200. Performance of this version seems a bit lacking. Start up time feels too long, files are slow to load sometimes, and cursor movement is also slow at times. Switching to develop
branch seems to improve performance by quite a margin, and also enable the latest features. Of course, you run the risk of some stuff being broken, but it's been worth it for the performance gains, and I haven't yet encountered any critical bugs that broke my work flow.
cd ~/.emacs.d git checkout develop
Run emacs now. On Windows, use the runemacs.exe instead of emacs.exe as the former doesn't spawn a terminal window. Spacemacs will run and install a bunch of things, and ask you some questions about the configuration you want. I went with the default ones.
1.1 Ubuntu/Elementary OS setup
Install Emacs from the app store. 25.2 was the available version at the time of writing. If you try running it, it'll most probably crash. If it doesn't, you probably don't need to do the next step.
cp /usr/share/applications/emacs25.desktop ~/.local/share/applications/emacs25.desktop
Open the newly copied .emacs25.desktop file and replace Exec line with this: Exec=/usr/bin/env XLIB_SKIP_ARGB_VISUALS=1 emacs25 %F
. You should now be able to launch Emacs without crashing. Add an alias to your .bashrc so that launching from command line works too: alias emacs="XLIB_SKIP_ARGB_VISUALS=1 emacs"
More info here: https://elementaryos.stackexchange.com/questions/797/how-to-get-gnu-emacs-work-on-elementary-os
When running spacemacs initial setup, you might encounter an error about "Bad signature". This isn't a spacemacs-specific issue and is related to some expired gpg key, and supposedly isn't a problem for emacs versions 26+. After trying many methods, the only thing the worked for me is adding (setq package-check-signature nil)
to the start of .spacemacs file. You can instead also try installing the package gnu-elpa-keyring-update and running the function, but that didn't work for me.
Org brain package wasn't getting installed for me for some reason. Since I don't use it, I added it to excluded packages, and spacemacs loaded successfully.
2 Spacemacs configuration
Open ~/.spacemacs file and give it a read. It's very well documented, and was somewhat easy to get a basic understanding of the settings within.
You might want to configure font settings first. The default is set to "Source Code Pro"
which may or may not be installed on your system. I changed mine to "Consolas"
with :size 12
. You might also want to change the :powerline-scale
setting if your modeline/powerline (the bar at the bottom of your screen) has some rendering issues. (This doesn't seem necessary for 0.300)
Next, enable/add the layers that you need under the dotspacemacs-configuration-layers
. Layers can be thought of a set of packages (plugins) that get enabled when in a particular major-mode, and that play well together. Some of the plugins may require certain applications to be installed before they can work properly (like tern or linters).
If you want to add a package without it being associated with a layer, you can add it under dotspacemacs-additional-packages
. Packages that you don't want installed go under dotspacemacs-excluded-packages
Custom configuration goes under dotspacemacs/user-config
. Here's mine at the time of writing:
(defun dotspacemacs/user-config () (evil-select-search-module 'evil-search-module 'evil-search) (setq hybrid-mode-enable-hjkl-bindings t) (setq dotspacemacs-mode-line-unicode-symbols nil) (setq scroll-margin 10) (setq helm-ag-base-command "c:/ProgramData/chocolatey/bin/ag.exe --vimgrep") (setq js-indent-level 2) (add-hook 'org-mode-hook 'spacemacs/toggle-truncate-lines-off) (add-hook 'org-mode-hook 'spacemacs/toggle-visual-line-navigation-on))
Here's a brief explanation of the settings above:
evil-select-search-module
makes search behave more like vim's rather than emacs.gn
command wan't working quite correctly without this setting.hybrid-mode-enable-hjkl-bindings
I'm not quite sure what this does. It's supposed to enable hjkl bindings outside of the main editor buffer as well, but I don't know exactly. I've set it to true, cause one can never have enough hjkl bindings I guess.dotspacemacs-mode-line-unicode-symbols
Enables/disables unicode symbols in the modeline. I disabled it cause they were looking ugly on Windows anyway. Someone on the internet also mentioned it might improve performance, but I couldn't really tell much difference.scroll-margin
This setting is similar to vim'sscrolloff
setting.helm-ag-base-command
Path to the installed Silver Searcher command. Silver searcher is better than the defaultgrep
search when searching for files or occurrences within a project causeag
respects your.gitignore
file and doesn't clutter your search results with results from unnecessary sources (such asnode_modules
). Remember to add the--vimgrep
flag or it won't work correctly. This step isn't necessary on Mac and Unix. (Update: I'm using ripgrep instead of ag now, and if you are running 0.300 of Spacemacs, you only need to ensure that ripgrep is in your $PATH, and this step is not required).js-indent-level
This sets the indentation level (shiftwidth). I'm still not sure about how to correctly configure tabstops and indentation levels in emacs yet, but from what I could gather it seems like indentation is controlled by different variables depending on the major mode, which is quite a bummer.js-indent-level
controls the indentation for js filesadd-hook
commands are somewhat similar toautocmd
in vim, and is used to set major-mode specific settings. Here I'm setting line-wrapping and makingjk
keys traverse visual lines instead of actual lines.
3 Spacemacs themes
Setting a new theme in spacemacs is really simple. Visit https://themegallery.robdor.com/ and choose a theme that you like. Then add the theme to dotspacemacs-themes
or replace an existing one. Here's what mine looks like: dotspacemacs-themes '(ujelly spacemacs-dark)
. The themes can be cycled through by using SPC T n
There's a layer called themes-megapack
, but I would caution against using that as it seemed to mess with my .spacemacs configuration by adding a bunch of things under custom-set-variables
, but I couldn't figure out what exactly and ended up resetting my .spacemacs file.
4 LSP setup
Check the https://github.com/emacs-lsp/lsp-mode link for various LSP servers. For javascript/typescript, the LSP server requires node to run. If you use nvm to manage your node instances, chances are that the node executable won't be found. You can verify this by running eshell
command and typing node
. If it says "Command not found", then your LSP server won't run. This happens because nvm alters the $PATH variable when running .bashrc, which isn't run when launching eshell
. Altering the exec-path
variable to add path to node binary didn't help me in this case. I found it easiest to create a symlink to node under /usr/local/bin
. Any globally installed node package that you expect to use from within emacs will need a symlink under /usr/local/bin
.
sudo ln -s ~/.nvm/versions/node/v12.13.1/bin/node /usr/local/bin/node
5 Useful external tools
Install the following external tools when setting up a new system:
- git
- nvm and node (create symlink to node under /usr/local/bin)
- ripgrep
- broot
- fzf
- diff so fancy
- rupa/z
- fd