Spacemacs - General Discussion, Blog Posts, Wiki

wiki
spacemacs
code-editors
Tags: #<Tag:0x00007fc83033ab58> #<Tag:0x00007fc83033a978> #<Tag:0x00007fc83033a770>

#1

##A wiki for Spacemacs

Spacemacs with Alchemist is an extremely popular set-up to use for Elixir development. Give it a try by following our guide here and let us know what you think!

http://spacemacs.org - Official SpaceMacs site
http://www.alchemist-elixir.org - Alchemist Elixir site


#Installation

We need to install Emacs first, then Spacemacs, then add the Elixir layer to SpaceMacs:

###1) Emacs installation

Here are the instructions for OS X (from their wiki). For other platforms look here.

Usual Emacs installation:

brew update
brew install emacs --with-cocoa
brew linkapps emacs

Or, SpaceMacs recommended installation (includes SpaceMacs icon etc):

$ brew tap d12frosted/emacs-plus
$ brew install emacs-plus
$ brew linkapps emacs-plus

###2) Spacemacs installation

Then simply backup your original emacs.d folder and install Spacemacs with:

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

Once that is done, start Emacs and let it install everything, then restart and Spacemacs config will kick in. Select VIM mode when it asks you.

###3) Adding the Elixir layer

Open up your ~/.spacemacs file, and under dotspacemacs-configuration-layers simply add elixir. It should look something like this:

   dotspacemacs-configuration-layers
   '(
     ruby
     ;; ----------------------------------------------------------------
     ;; Example of useful layers you may want to use right away.
     ;; Uncomment some layer names and press <SPC f e R> (Vim style) or
     ;; <M-m f e R> (Emacs style) to install them.
     ;; ----------------------------------------------------------------
     helm
     ;; auto-completion
     ;; better-defaults
     emacs-lisp
     ;; git
     ;; markdown
     ;; org
     ;; (shell :variables
     ;;        shell-default-height 30
     ;;        shell-default-position 'bottom)
     ;; spell-checking
     ;; syntax-checking
     ;; version-control
     elixir
     )

Then simply restart SpaceMacs and it will install everything. That’s it, you now have SpaceMacs installed!!

###4) Install Ack or Ag

This will speed up search significantly.

Ack is a tool like grep, optimized for programmers.
Ag is like Ack, but claims to be 5-10x faster.

I’ve opted for Ag, install it in OS X with brew install the_silver_searcher

###5) Optional - enable smooth scrolling, NeoTree to right and session restore

Smooth scrolling (source)

Simply add the last 5 lines below to your user-config to defun dotspacemacs/user-config () to end up with something like:

(defun dotspacemacs/user-config ()
  "Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."
  ;; scroll one line at a time (less "jumpy" than defaults)
  (setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ;; one line at a time
  (setq mouse-wheel-progressive-speed nil) ;; don't accelerate scrolling
  (setq mouse-wheel-follow-mouse 't) ;; scroll window under mouse
  (setq scroll-step 1) ;; keyboard scroll one line at a time
  )

NeoTree on right hand side

If you would like your NeoTree SPC f t to open on the right hand side simple add '(neo-window-position (quote right)) to you custom-set-variables in your .spacemacs file (then restart or reload).

Session restore

Set dotspacemacs-auto-resume-layouts to t in your .spacemacs - this will restore your session when you open SpaceMacs. (You may or may not like this - might be an idea to try it without for a while first.)

###6) For Mac users

Adding a font

The default font does not seem to be one shipped with OS X, so open your .spacemacs file (which can also be opened from within SpaceMacs with SPC f e d and under dotspacemacs-default-font swap the font to “Menlo” and change the size to 12.

Adding the OSX layer

In layers, add osx as this will add some common Mac keybindings (such as command and w to close a window, command and + or - to increase/decrease font size etc.

For those with British Keyboards

Add the following to your user-config so that you can use ALT+3 for the hash key:

  ;; Allow hash to be entered
  (define-key window-numbering-keymap (kbd "M-3") nil) 
  (global-set-key (kbd "M-3") (lambda () (interactive) (insert "#")))

Making the Emacs shell respect your .bash_profile

Install exec-path-from-shell by SPC SPC package-install (then start typing exec-path-from-shell)
Then open or create a .bashrc file and at the bottom add . ~/.bash_profile


###Getting started with Spacemacs and documentation


###Installing packages

Find the package you want to install on Melpa (the Emacs Package Manager) and then check it is not already installed by SPC h SPC followed by the package name. If it’s not…

  • If it’s a layer add it to the layers list in your .spacemacs file and restart
  • Otherwise hit SPC SPC <package name> RET and it will install it

Most packages are on Melpa and included by SpaceMacs, but if not, you can add the package name to dotspacemacs-additional-packages and restart to see if it installs, if not then additionally add any downloadable associated files to a directory in your load path.


###Spacemacs quick tips

See the thread for more, here are a few worth pointing out:

Opening and reloading config

  • You can open your .spacemacs file from within SpaceMacs with SPC f e d
  • After making changes with the above, you can use SPC f e R to reload your config (saves having to restart it - but if you want to restart it, you can do SPC q r)

Lookup, viewing docs and misc

  • SPC h SPC to open documentation
  • Need to lookup up an Emacs function? If you are curious as to what a function is bound to, you can do SPC h d f name-of-function RETURN, e.g. SPC h d f what-cursor-position RETURN
  • When you see things that ask you to do something like M-x customise-face that means you have to press SPC SPC and then type in customise-face .
  • , is the mode leader, so when something is referenced as SPC m <something> you can simply use , <something>

Searching

  • SPC p p - Show projects you have opened previously
  • SPC p f - Find file in project
  • SPC s s - Swoop search (search in file) (you can also do the usual vim /)
  • SPC f f - Find file (fuzzy search)
  • SPC f r - Find/show recent files
  • SPC / - Find pattern (text) in open file (shortcut for SPC s p)
  • SPC * - Same as SPC / but searches what’s under the cursor
  • If you ned to search a term exactly, escape the space, e.g.: SPC / see\ the\ posts
  • SPC s a p find pattern (text) in project

Windows

  • SPC w s to split window SPC w v to split vertically
  • SPC w d to delete/close window (or Command W in OS X)

Buffers

  • SPC b b to list buffers
  • SPC TAB to go to last buffer

NeoTree

  • SPC f t open NeoTree
  • SPC 0 to select NeoTree window
  • SPC 1 to select first (other) window

Shells

  • SPC ' open shell (opens in the directory of the file you’re in)
  • SPC p ' open shell in root of project

Commenting/uncommenting

  • gcc or SPC cl comment/uncomment line
  • gc3j to comment an additional 3 lines down (end with k for up)
  • v highlight code then gc

###Spacemacs Tutorials

###Spacemacs Blog Posts

###Spacemacs Themes

###SpaceMacs Gitter Chat
https://gitter.im/syl20bnr/spacemacs - they are very active and helpful in their channel so definitely pay them a visit if you need help

###Troubleshooting

If you get any warnings on startup, try SPC b b for buffers and look in ‘messages’.


###Alchemist Elixir basic usage

###Alchemist docs


Refactoring Elixir code using Spacemacs or other IDEs
Share your .spacemacs file with me!
Curated HEX packages
Emacs - General Discussion, Blog Posts, Wiki
Atom Code Editor - General Discussion, Blog Posts, Wiki
Which code editor (or IDE) do you use?
Elixir Code Editors & IDEs 2017 - which one are you using? (Poll)
Elixir Code Editors & IDEs 2017 - which one are you using? (Poll)
Refactoring Elixir code using Spacemacs or other IDEs
Elixir Code Editors & IDEs 2017 - which one are you using? (Poll)
Atom Beam.smp using up 100% resources
What Elixir related stuff are you doing?
What Elixir related stuff are you doing?
Which code editor (or IDE) do you use?
What editing tools can I use to understand Elixir better?
Which tutorial/book/course do you recommend if someone is learning Emacs for Elixir development?
Elixir Code Editors & IDEs 2017 - which one are you using? (Poll)
Atom Beam.smp using up 100% resources
What Elixir related stuff are you doing?
What Elixir related stuff are you doing?
#2

Just found this blog post, which looks like it contains some really good info (anyone feel anything is missing from it?)

And the Emacs Alchemist Cheat Sheet:

https://github.com/tonini/alchemist.el/blob/master/doc/alchemist-refcard.pdf


#7

My spacemacs cheatsheet!


#8

That looks really helpful - thanks!

Is it possible to get Neotree to always open on the right hand side? With Vim we can add this to .vimrc let g:NERDTreeWinPos = "right"


#9

You asked about screen splitting in editors topic. You not only can manage windows like in Vim (hit spc w instead of ctrl+w, i.e. spc w v to split vertically) but there is awesome golden-ratio mode ( spc t g to toggle) where windows are resized using golden ratio and the largest is your current window.

By the way. No one mentioned magit which is the best git client ever!


#10

@AstonJ I believe there is a way to do it. I don’t know specifically though. See: https://github.com/jaypei/emacs-neotree/issues/87


#11

By the way. No one mentioned magit https://github.com/magit/magit which
is the best git client ever!

Best git client ever is git from command-line. I have not found any git
integration for any IDE or editor that’s that flexible as plain old git
executable.


#12

Thanks all - I’m sure there’ll be a way, though (and I’ve only literally spent 5 minutes with it) but I may not even use it like I use Vim… already getting a different vibe - which I quite like :003:

From what I’ve seen so far it’s got a really, really nice feel. Will report back once I’ve had a good play tho. Definitely encourage everyone else to check it out as well. I love that hitting the space bar gives you a list of commands available - such a great idea!


What Elixir related stuff are you doing?
#13

It took me 2 days to be fully productive in spacemacs after almost 10 years in Vim. Give it a try it is perfect match - finally best operating system got its good text editor.


#14

Here’s a tip from me:

user_allex = some_function_to_name "allex ocean"

In this example, to change the word allex ocean you can place a cursor anywhere in the word and hit ca" (change around ") and then just type the new text.

similarly we have

  • caw (change around word)
  • daw (delete around word)
  • cap (change around paragraph)

Refactoring Elixir code using Spacemacs or other IDEs
#15

Similarly, you have the ‘i’ (inner) variants:

  • ciw (change within word)
  • cit (change within tags)
  • cib (change within parentheses)
  • ciB (change within curly brackets)
  • ci] (change within brackets)

I also use ‘ct’ (change until a character) and ‘cf’ (change until and including a character) a lot (these only work for characters on the same line).
All these commands are available on Vim as well.


#16

we also have the ‘s’ (surrounding) variants:

  • cs( (change surrounding bracket )

Example
(alpha beta gama)

cs([

[alpha beta gama]


#17

when i use
cs([

it adds spaces around the inner contents and the square brackets
e.g
(foo) -> [ foo ]

Is this expected?, is there any option to disable those spaces?


#18

Use the closing ) if you don’t want the space, e.g. cs)]

:smiley:


#19

Does Spacemacs not help when defining modules and functions etc?

For example, if I type def and then hit tab in Vim it will set things up for me like:

def name do
  
end

Is there anyway to get Spacemacs to do this?

EDIT: Looks like you have to type to whole first line and it will add the end for you…

EDIT2: Another question:

How do you change the spacing of a line? For example, in MacVim I can go on to a line and hit cmd and either the [ or ] to move the line either 2 spaces to the left or right.

Answer: looks like you have to be in insert mode and use CTRL T or CTRL D. Alternatively, you can use visual (V) with < or >.


#20

Is there an easy way to comment/uncomment lines?

It seems you have to go in visual mode, highlight the lines you want, then insert your comment and press escape.

CTRL V highlight lines SHIFT I type in your comment and then hit ESC.

Also just found something really annoying - I can’t get a hash # key with ALT 3 :frowning:

Btw on MacVim you just highlight the lines you want to comment and hit CMD / (it works out the most appropriate comment for you).


#21

There’s also the inbuilt evil-nerd-commenter which works really well.

http://spacemacs.org/doc/DOCUMENTATION#orgheadline162


#22

Awesome! Thanks @ridget!

So SPACE c l will comment out a line :023:

Any ideas on how best to get ALT 3 give me the # key? There are some old posts from 2010 on the web, not sure if a better way has emerged yet?

Edit: just add this guide to the Wiki too http://spacemacs.org/doc/VIMUSERS.html


#23

Unless you’re particularly interested in keeping it for selecting window #3, I’d just rebind it in your config under user-config.

Use SPC f e d to get there and SPC f e R to reload your config immediately

This is a good little sample of how you can set up your keys for evil-mode with the default evil-maps, hope this all helps.


#24

All of those combinations work with the ‘d’ (delete) command too. So diw would be delete within word etc.

You can also type the literal parens or curly braces rather than using ‘b’ and ‘B’, so di{ and di( work and do what you’d expect.

there’s also the t motion, where dtw would be Delete To Word, and so forth.