Spacemacs Tutorial
I’m learning Spacemacs (with Vim key bindings (check out this blog post by Stéphane Caron)) and would like to share some of my notes here.
For detailed instructions and a deeper understanding please refer to Spacemacs’ official documentation.
Modal editing with Vim
ESC
Key returns you from other modes to the normal mode.
You can learn Vim key bindings with (SPACE h T v)
, the Emacs Evil Tutor :-p.
Of course there are many other wonderful and interactive tutorials out there…
Navigation in NORMAL
mode
word-level
w
forward motion by wordb
backward motion by worde
forward motion by end of word
line-level
0
the beginning of line$
end of line^
first non-empty character of the line
buffer-level
(Ctrl U)
scrolls up(Ctrl D)
scrolls downgg
beginning of bufferG
end of buffer
moving the cursor
H
to the highest line of the screenM
to the middle line of the screenL
to the lowest line of the screen
find f|F
f
find in forward directionF
find in backward direction
1 | fo |
to t|T
(a variant of find)
Editing Commands
Open
o
opens a line below and entersINSERT
mode.O
opens a line above and entersINSERT
mode.
Delete
Deletion combines with movement commands.
dw
deletes a wordde
deletes from cursor position to end of the worddd
deletes the linex
deletes a single character at cursor position (like on a typewriter!)
Change
Change combines with movement commands. Think of it as delete and enter into INSERT
mode.
cw
changes the word, i.e. deletes the word and puts you inINSERT
mode.ce
deletes the word from cursor position to end of the word and entersINSERT
mode.cc
deletes the line and entersINSERT
mode.
Replace
r
replaces single character at cursor position, after replacement inNORMAL
mode.R
enters and remains inREPLACE
mode until you switch mode.
Undo and Redo
u
to undo changes.Ctrl r
to redo.
Copy and Paste
y
for Yank and p
for Paste
These two also combines with movement commands.
yy
copies current line.yw
copies the word.p
pastes at cursor position.
If you want to move a line, you can use
dd
to delete the line and thenp
to paste it wherever you want.
--VISUAL--
for text selection
To select blocks of text we use VISUAL
mode and navigate to make a selection.
Then we can use y
for copying the selection and automatically returns to NORMAL
mode.
--VISUAL LINE--
selects by lines--VISUAL BLOCK--
selects by rectangular blocks of text
1 | `~` flips the case of selected text. |
Counts
We can use numbers for quick and specific movements.
For instance, <number>j
= pressing j
<number> times.
Therefore:
4k
moves cursor up 4 linesv3e
entersVISUAL
mode, select 3 words (select to the end of the third word).d7w
or7dw
deletes 7 words counting from the word the cursor is at.
Since counts are so useful, there’s a trick that facilitates the use of line numbers. Instead of counting or mentally subtracting line numbers, we can use relative line numbers!
Relative Line Numbers
Setting up relative line numbers
In .spacemacs
, set dotspacemacs-line-numbers 'relative
.
Modifiers
a
for Around and i
for Inside
ci[
changes (deletes) everything inside square brackets, enterINSERT
mode.di(
deletes everything inside parentheses, remains inNORMAL
mode.da(
deletes also the parentheses around, remains inNORMAL
mode.
Miscellaneous
Matching Parenthesis
If you have your cursor on one of them, %
will show you its match.
Case Flip
~
flips the case of selected text.
The lazy dot .
.
simply repeats the previous editing command that Vim made.
The dotspacemacs
file
.spacemacs
is Spacemacs’ configuration file.
The dotfile is written in emacs-lisp language, ;;
is used for comments.
Most used commands related to the dotfile:
(SPACE f e)
shortcut combo opens a list of commands.d
-> opens the dotfileR
-> reloads configuration
Usually the most important section of the dotfile is under dotspacemacs-configuration-layers
.
Spacemacs GUI - Spaceline
Spaceline is spacemacs’ powerline.
The number displayed on the left corner is the window number.
Other information on the line:
- status of the file
*
shows that the file has been modified but the changes are not saved.
- size of the file
- filename
- the current major mode
Emacs-Lisp
,Org
,Markdown
etc.- In
Emacs-Lisp
major mode, use(SPACE c L)
to toggle comments.
- In
- On the right of the powerline: cursor position
<line>:<character> <percentage through the file>
Under the spaceline there’s usually an indication of the current editing mode, in the above example it is the INSERT
mode.
Bits and pieces
Save Buffer
Using the familiar commandline mode (led by the :
key):
:w
writes buffer to file.:q!
quits without saving any changes.:q
quits (current window).:qa
quits all windows.
A more Spacemacs-way of saving the buffer is (SPACE f s)
.
Font
Setting default font and font size
- Search through the dotfile using vim syntax:
/font
. - Modify
dotspacemacs-default-font
. - Save the dotfile and restart emacs.
Zoom-in and -out
(SPACE z f)
enters zoom frame transient state. Type q
to quit.
Toggle line wrap
(SPACE t l)
toggles line wrap.