2016-05-18 21:46:13 +00:00
#+TITLE : Beginners tutorial
2018-09-19 03:54:47 +00:00
* Table of Contents :TOC_4_gh:noexport:
2017-05-22 14:16:12 +00:00
- [[#why-spacemacs ][Why Spacemacs? ]]
- [[#installation-and-setup ][Installation and setup ]]
- [[#getting-started ][Getting started ]]
2018-10-23 14:18:21 +00:00
- [[#key-binding-notation ][Key binding notation ]]
2017-05-22 14:16:12 +00:00
- [[#modal-text-editing---why-and-how ][Modal text editing - why and how? ]]
- [[#start-the-vim-tutorial ][Start the Vim tutorial ]]
- [[#using-the-spacebar-to-launch-commands ][Using the spacebar to launch commands ]]
- [[#buffers-windows-and-frames ][Buffers, windows and frames ]]
- [[#accessing-files ][Accessing files ]]
- [[#configuring-spacemacs ][Configuring Spacemacs ]]
- [[#adding-language-support-and-other-features-using-layers ][Adding language support and other features: using layers ]]
- [[#changing-the-colour-theme ][Changing the colour theme ]]
- [[#starting-maximized ][Starting maximized ]]
- [[#quitting ][Quitting ]]
- [[#additional-features-tips-and-troubleshooting ][Additional features, tips and troubleshooting ]]
- [[#org-mode ][Org mode ]]
- [[#version-control---the-intelligent-way ][Version control - the intelligent way ]]
- [[#daemon-mode-and-instant-startup-linux ][Daemon mode and instant startup (Linux) ]]
- [[#swap-caps-lock-and-esc-keys-on-your-keyboard ][Swap caps lock and esc keys on your keyboard ]]
- [[#troubleshooting-and-further-info ][Troubleshooting and further info ]]
2016-05-18 21:46:13 +00:00
* Why Spacemacs?
- Unparallelled text and structure editing for all types of writing tasks:
2017-01-02 05:17:22 +00:00
creative writing, blogging, note-taking, todo-lists, scientific papers...
2016-05-18 21:46:13 +00:00
- Powerful modes for programming in dozens of programming languages
- Deeply customizable yet beginner-friendly
2017-01-02 05:17:22 +00:00
2017-04-20 06:40:14 +00:00
* Installation and setup
2018-09-19 03:54:47 +00:00
Spacemacs is a beginner-friendly and powerful extension of a popular text
editor called Emacs. To install Spacemacs you need to first install base Emacs
and then download the Spacemacs extension files, which is most easily done by
using a program called Git. The steps are easy and detailed in the [[https://github.com/syl20bnr/spacemacs/blob/master/README.md#prerequisites ][readme ]].
2016-05-18 21:46:13 +00:00
* Getting started
2018-10-23 14:18:21 +00:00
** Key binding notation
The power of Spacemacs lies in its efficient key bindings. Because it is built on
Emacs, we will use Emacs conventions for key binding notation. The most important
2016-05-18 21:46:13 +00:00
modifier keys are:
~SPC~ = ~Space~ , used as the leader key in Vim editing style.
2017-01-05 15:44:16 +00:00
~RET~ = ~Return~ (also known as ~Enter~ )
2016-05-18 21:46:13 +00:00
~C-~ = ~Ctrl~
2018-09-19 03:54:47 +00:00
~M-~ (for “meta”) = ~Alt~
2016-05-18 21:46:13 +00:00
~S-~ = ~Shift~
The modifier keys can be used either in a sequence or as key chords by pressing
two keys at the same time. ~SPC 1~ is notation for a key sequence and means
pressing ~Space~ first and pressing ~1~ after it. Key chords are notated by
2016-11-07 15:05:27 +00:00
writing a ~-~ between the keys. Thus ~C-c~ means pressing ~Ctrl~ and the letter
~c~ simultaneously. Key chords and sequences can also be combined: ~C-c a~ means
2018-09-19 03:54:47 +00:00
“First press ~Ctrl~ and ~c~ simultaneously, then press ~a~ ”. ~C-c C-a~ means
“First press ~Ctrl~ and ~c~ simultaneously, then press ~Ctrl~ and ~a~
simultaneously”.
2016-05-18 21:46:13 +00:00
2018-09-19 03:54:47 +00:00
This document assumes you chose the “Vim” editing style and notates accordingly.
2016-05-18 21:46:13 +00:00
If you chose the Emacs editing style, just substitute ~SPC~ with ~M-m~ in all
the commands that begin with ~SPC~ .
2016-11-07 15:05:27 +00:00
(Note: Other modifier keys such as ~Super~ , notated with a small-case ~s-~ , can
be set up but this is rarely necessary in Spacemacs).
2016-05-18 21:46:13 +00:00
2017-01-02 05:17:22 +00:00
** Modal text editing - why and how?
2016-11-07 15:05:27 +00:00
Writing (or programming) is typically not a simple linear process of adding
words and lines until finished. At least as important part of the work consists
of editing the text: deleting and rewriting parts, moving sentences around or
jumping to an earlier point to fix a discrepancy.
2016-05-18 21:46:13 +00:00
The crudest way to, for example, delete a certain line is moving the mouse to
the line in question, clicking on the line and then deleting it by pressing
backspace repeatedly. This is slow and inefficient, both because you have to
take your hands from your keyboard and because repeatedly pressing backspace
takes time. The more time you spend pressing keys, the more time and energy is
2017-01-02 05:17:22 +00:00
wasted.
2016-05-18 21:46:13 +00:00
To speed up editing, many editors use key chords for common editing tasks:
~Control-c~ for copying and so on. However, these types of shortcuts tend to
2016-11-07 15:05:27 +00:00
have two problems. First, you have to press two keys at the same time, which is
harder to coordinate and thus slower than pressing keys in a sequence. Second,
you typically have to use your weakest fingers (pinkies) extensively and bend
your wrists in unergonomic positions, which is uncomfortable for many and risks
developing carpal tunnel syndrome in the long run.
2016-05-18 21:46:13 +00:00
2016-11-17 17:16:54 +00:00
By contrast, Spacemacs uses modal editing. Modal editing means that different
2016-05-18 21:46:13 +00:00
modes are used for editing and writing text. While this can sound complicated at
first, in practice it can be learned quickly and once learned is unparallelled
in speed and ergonomy. Our earlier example of deleting a certain line of text (a
very common edit task) can be achieved in Spacemacs by simply navigating to the
line in question with the keys ~j~ and ~k~ (navigation keys) and pressing ~d~
2018-09-19 03:54:47 +00:00
(for “delete”) two times!
2016-05-18 21:46:13 +00:00
2016-11-07 15:05:27 +00:00
You might have noticed that this was achieved entirely without moving your
fingers from your home row (the row where your fingers lie in rest when
touch-typing) and without using modifier keys.
2016-05-18 21:46:13 +00:00
2017-01-02 05:17:22 +00:00
** Start the Vim tutorial
2016-05-18 21:46:13 +00:00
The modal editing features of Spacemacs originate from a text editor called Vi,
and thus the modal editing tutorial is called eVIl tutor. Press ~SPC h T~ (that
2017-01-02 05:17:22 +00:00
is, the spacebar followed by ~h~ and ~T~ ) to familiarize yourself with
2017-04-28 20:20:20 +00:00
modal editing.
2016-05-18 21:46:13 +00:00
** Using the spacebar to launch commands
2016-11-07 15:05:27 +00:00
Now that you are familiar with writing and editing text it is time to put the
2018-09-19 03:54:47 +00:00
“Space” into Spacemacs. Because the spacebar is the most accessible key on the
2016-11-07 15:05:27 +00:00
keyboard and is pressed by the strongest fingers (the thumbs), it is a natural
choice for launching commands. You can think of it as the start menu of
Spacemacs.
2016-05-18 21:46:13 +00:00
2017-01-02 06:29:07 +00:00
A short instant after the spacebar is pressed a menu pops up. This interactive
menu shows you what submenus and commands can be accessed by subsequent
keypresses. Browsing around this menu is a great way of finding new features in
Spacemacs, so keep on eye on the different options! ~ESC~ usually breaks the
2018-09-19 03:54:47 +00:00
combination you don’ t want to use.
2017-01-02 06:29:07 +00:00
2016-05-18 21:46:13 +00:00
** Buffers, windows and frames
2018-10-18 17:07:35 +00:00
Because Emacs (the extension of which Spacemacs is) was developed in the ’ 80s
2017-01-02 05:17:22 +00:00
before the advent of modern graphical user interfaces, Emacs has
2018-09-19 03:54:47 +00:00
a different name of what we normally call “windows”: in Emacs these are
called “frames”. A frame is what pops up when you launch Spacemacs from your
2016-05-18 21:46:13 +00:00
desktop shortcut. A frame contains windows and buffers.
Windows are the visual spaces a frame is divided into. The default
is one, but windows can be split to allow editing multiple files in one frame.
2018-09-19 03:54:47 +00:00
Let’ s try this. Press ~SPC~ to bring up the menu. You can see different letters
2016-05-18 21:46:13 +00:00
having different submenus associated with them, usually with a mnemonic for
2018-09-19 03:54:47 +00:00
easier recall. The letter w is assigned for “windows”: press it. A new menu
2016-05-18 21:46:13 +00:00
opens with further options. Write the character / to split the currently active
window vertically into two.
Now you should see two windows of this tutorial, and the one on the left should
be active, as can be seen from the modeline in the bottom or by moving the
2018-09-19 03:54:47 +00:00
cursor around using the navigation keys. This isn’ t very useful, as we
2016-05-18 21:46:13 +00:00
would probably want to see a different file on the right.
2016-11-07 15:05:27 +00:00
First, activate the window on the right with ~SPC 2~ . Now that the window on the
2018-09-19 03:54:47 +00:00
right is active, we can open a different buffer for a different file. We’ ll use
2016-05-18 21:46:13 +00:00
the scratch buffer, which can be used like a notepad. Be warned, unlike other
2018-09-19 03:54:47 +00:00
buffers it doesn’ t prompt you whether you want to save the changes you’ ve made
2016-11-07 15:05:27 +00:00
when quitting the program! Press ~SPC b~ to open the buffers menu and then
switch to the scratch buffer by pressing s. Now you have two different buffers
in two different windows open, great! You can write something on the scratch
2018-09-19 03:54:47 +00:00
buffer, and when you’ re done, make sure that the scratch window is active and
2016-11-07 15:05:27 +00:00
close it by pressing ~SPC w d~ .
Now the tutorial window fills the whole frame. But you only closed the window,
not the scratch buffer, so the buffer is still open beneath the surface. You can
quickly switch between the current buffer and the last with ~SPC TAB~ : use this
a couple of times to switch between the tutorial and the scratch buffer. ~SPC b~
has more options for switching between buffers, for example ~SPC b b~ opens a
2017-01-02 05:17:22 +00:00
searchable list of all currently open buffers and ~SPC b d~ closes the current
buffer.
2016-05-18 21:46:13 +00:00
2017-01-02 06:29:07 +00:00
** Accessing files
Files can be accessed under the ~SPC f~ mnemonic. You can navigate to any file
2017-01-05 15:44:16 +00:00
with ~SPC f f~ and open it by pressing ~RET~ . Accessing recently opened files is
2017-01-02 06:29:07 +00:00
a very common task and is done with ~SPC f r~ . An edited file is saved with
~SPC f s~ .
2016-05-18 21:46:13 +00:00
* Configuring Spacemacs
** Adding language support and other features: using layers
Spacemacs divides its configuration into self-contained units called
configuration layers. These layers are stacked on top of each other to achieve a
custom configuration.
2017-04-20 06:40:14 +00:00
By default Spacemacs uses a dotfile called =~/.spacemacs= to control which layers
2016-05-18 21:46:13 +00:00
to load. Within this file you can also configure certain features. First, split
the window vertically to view both this tutorial and the dotfile simultaneously
2016-11-07 15:05:27 +00:00
(~SPC w /~ ). Open the dotfile by pressing ~SPC f e d~ . Navigate to the line
2018-09-19 03:54:47 +00:00
starting with “dotspacemacs-configuration-layers”. The following lines have
2017-04-20 06:40:14 +00:00
further instructions: uncomment =org= and =git= layers if you want to be
2017-08-05 19:48:37 +00:00
familiarized with them. More [[https://github.com/syl20bnr/spacemacs/blob/develop/doc/LAYERS.org ][layers ]] for different languages and tools can be
2017-01-05 15:44:16 +00:00
found by pressing ~SPC h SPC~ . The added layers will be installed upon restart
of Spacemacs.
2016-05-18 21:46:13 +00:00
2018-09-19 03:54:47 +00:00
Some layers require third-party tools that you’ ll have to install via your
2017-04-20 06:40:14 +00:00
favorite package manager. The layer readme will tell if this is the case.
2016-05-18 21:46:13 +00:00
** Changing the colour theme
You can toggle the theme by ~SPC T n~ . This cycles between currently
activated themes. You can find more by adding the themes-megapack layer and
activate them by writing their names in the dotspacemacs-themes list.
** Starting maximized
2017-04-20 06:40:14 +00:00
Editing the =dotspacemacs-maximized-at-startup= variable from =nil= to =t= will start
2016-05-18 21:46:13 +00:00
Spacemacs maximized.
2017-01-02 05:17:22 +00:00
** Quitting
2018-09-19 03:54:47 +00:00
Save the changes you’ ve made to the dotfile with ~SPC f s~ and then quit emacs
2016-11-07 15:05:27 +00:00
by ~SPC q q~ . You can return to this tutorial by clicking it on the home screen!
2016-05-18 21:46:13 +00:00
* Additional features, tips and troubleshooting
** Org mode
Org mode is one of the best features of Spacemacs and enough reason to warrant
2018-09-19 03:54:47 +00:00
its use. Org mode’ s official description tells that it is “for keeping notes,
2017-01-02 05:17:22 +00:00
maintaining todo lists, planning projects, and authoring documents with a fast
2018-09-19 03:54:47 +00:00
and effective plain-text system”, but this gives only a small inkling of its
2017-01-02 05:17:22 +00:00
versatility. If you do any kind of writing at all, chances are that Org mode
will make it easier and more fun. This tutorial was written in Org mode.
2016-05-18 21:46:13 +00:00
2017-04-18 06:05:28 +00:00
Install the Org layer and open this tutorial. Make a copy named test.org with
~SPC f c~ somewhere outside of the .emacs.d directory. Write
~SPC SPC org-mode RET~ to switch to org mode from the write-only documentation mode.
2016-05-18 21:46:13 +00:00
2017-01-05 15:44:16 +00:00
Press ~S-TAB~ repeatedly and observe that this cycles the visibility of the
contents of different headlines. Press ~t~ in normal mode and observe that you
can add TODO tags on headlines. Press ~M-k~ or ~M-j~ in normal mode and see how
you can quickly move parts of the document around.
This is not even scratching the surface of Org mode, so you should look into
2017-08-05 19:48:37 +00:00
[[https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bemacs/org/README.org ][org layer ]] with ~SPC h SPC org~ for more information. Googling for Org mode
2017-01-05 15:44:16 +00:00
tutorials is also very helpful in finding out the most useful features of it!
2016-05-18 21:46:13 +00:00
** Version control - the intelligent way
Version control means keeping track of the changes and edits you have made to
your document. Often version control is done by saving different versions of the
2018-09-19 03:54:47 +00:00
document with different names, such as “document version 13” and so on. This is
2016-11-07 15:05:27 +00:00
crude in many ways: if you want to, for example, re-add something you deleted,
you have to manually open several past versions of the document to find the one
with the deleted part, and then copy-paste it to the most recent file. More
complicated edits will be harder still. Fortunately, there is a much better way.
2016-05-18 21:46:13 +00:00
Git is the most popular version control system for programmers, but it can be as
useful for people that are writing school or scientific papers, fiction or blog
posts as well.
Install the git layer, restart Spacemacs and open a file you want to version
control. You can check the status of your file by pressing ~SPC g s~ . Select the
folder your file is in. You will be prompted whether you want to create a
2018-09-19 03:54:47 +00:00
repository in the folder. Select yes. You will see a list of “Untracked files”:
navigate to the file you want to track and press s to “stage changes”. You might
2016-05-18 21:46:13 +00:00
be prompted to save the file: save it if necessary. Now the new file needs to be
2018-08-01 18:51:57 +00:00
committed: press c and c again. Two windows pop up: one showing the changes
2018-09-19 03:54:47 +00:00
you’ ve made since the last edit (in this case, the whole document) and another
prompting for a commit message. Write “Initial commit”, press ESC to exit back
2016-05-18 21:46:13 +00:00
to normal mode and press ~, c~ confirm and quit the commit
2017-01-02 05:17:22 +00:00
message. To abort, press ~, a~ .
2016-05-18 21:46:13 +00:00
Now you know how to make a commit. The commits are saved in
the (hidden) .git folder in the same folder the tracked file(s) are in. You can
make further commits the same way.
2017-01-02 05:17:22 +00:00
** Daemon mode and instant startup (Linux)
2016-05-18 21:46:13 +00:00
Emacs can be used in daemon mode: a daemon runs in the background and launches
2017-01-02 05:17:22 +00:00
clients. This way new frames launch instantly without delay. [[https://www.emacswiki.org/emacs/EmacsAsDaemon ][Emacswiki ]] tells
more about the daemon and how to set it to launch automatically on startup.
2016-05-18 21:46:13 +00:00
** Swap caps lock and esc keys on your keyboard
This is useful outside of Spacemacs as well!
2017-01-02 05:39:20 +00:00
** Troubleshooting and further info
2018-10-23 14:18:21 +00:00
~SPC ?~ shows you the key bindings in the current major mode, which is often
2018-02-15 09:54:56 +00:00
helpful. For troubleshooting, please refer to the [[https://github.com/syl20bnr/spacemacs/blob/develop/doc/FAQ.org ][FAQ ]] by pressing ~SPC h f~ .
2017-01-05 15:44:16 +00:00
More help is found under ~SPC h~ , and with ~SPC h ~SPC~ you can access the
comprehensive Spacemacs documentation, including this tutorial and the layer
2017-01-02 06:29:07 +00:00
documents.
The [[https://gitter.im/syl20bnr/spacemacs ][Gitter chat ]] can be used to ask questions if the answer cannot be found in
2018-09-19 03:54:47 +00:00
the documentation. For a detailed review of Spacemacs’ s features one can also
2017-01-02 06:29:07 +00:00
watch the [[https://www.youtube.com/playlist?list=PLrJ2YN5y27KLhd3yNs2dR8_inqtEiEweE ][Spacemacs ABC series ]] by Eivind Fonn on Youtube. Some of the
keybindings have changed since the videos were uploaded but seeing someone in
action helps spot helpful tricks that would otherwise be missed.