2015-10-30 13:23:24 +00:00
|
|
|
#+TITLE: Migrating from Vim
|
2015-11-08 18:04:44 +00:00
|
|
|
#+HTML_HEAD_EXTRA: <link rel="stylesheet" type="text/css" href="../css/readtheorg.css" />
|
2015-10-30 11:20:58 +00:00
|
|
|
|
|
|
|
* Migrating from vim :TOC_4_org:noexport:
|
|
|
|
- [[Purpose of this document][Purpose of this document]]
|
|
|
|
- [[Philosophy][Philosophy]]
|
|
|
|
- [[Basic orientation][Basic orientation]]
|
|
|
|
- [[Terms][Terms]]
|
|
|
|
- [[Modes vs. States][Modes vs. States]]
|
|
|
|
- [[Layers][Layers]]
|
|
|
|
- [[Micro-states][Micro-states]]
|
|
|
|
- [[Keybinding conventions][Keybinding conventions]]
|
|
|
|
- [[Running commands][Running commands]]
|
|
|
|
- [[Buffer and window management][Buffer and window management]]
|
|
|
|
- [[Buffers][Buffers]]
|
|
|
|
- [[Special buffers][Special buffers]]
|
|
|
|
- [[Windows][Windows]]
|
|
|
|
- [[Files][Files]]
|
|
|
|
- [[The Help System][The Help System]]
|
|
|
|
- [[Exploring][Exploring]]
|
|
|
|
- [[Customization][Customization]]
|
|
|
|
- [[The .spacemacs file][The .spacemacs file]]
|
|
|
|
- [[Emacs Lisp][Emacs Lisp]]
|
|
|
|
- [[Variables][Variables]]
|
|
|
|
- [[Keybindings][Keybindings]]
|
|
|
|
- [[Functions][Functions]]
|
|
|
|
- [[Activating a Layer][Activating a Layer]]
|
|
|
|
- [[Creating a Layer][Creating a Layer]]
|
|
|
|
- [[Installing a single package][Installing a single package]]
|
|
|
|
- [[Loading packages][Loading packages]]
|
|
|
|
- [[Uninstalling a package][Uninstalling a package]]
|
|
|
|
- [[Common tweaks][Common tweaks]]
|
|
|
|
- [[Changing the escape key][Changing the escape key]]
|
|
|
|
- [[Changing the colorscheme][Changing the colorscheme]]
|
|
|
|
- [[Nohlsearch][Nohlsearch]]
|
|
|
|
- [[Sessions][Sessions]]
|
|
|
|
- [[Navigating using visual lines][Navigating using visual lines]]
|
|
|
|
- [[Other useful links][Other useful links]]
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
* Purpose of this document
|
|
|
|
This document is intended to supplement the Spacemacs documentation by bridging
|
|
|
|
the gap between vim and Spacemacs. While some information may be duplicated,
|
|
|
|
this does not replace the Spacemacs documentation. It is recommended that you
|
|
|
|
read both files to fully understand Spacemacs.
|
|
|
|
|
2015-07-04 11:46:15 +00:00
|
|
|
[[file:DOCUMENTATION.org][Spacemacs Documentation]]
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
* Philosophy
|
|
|
|
One misconception many vim users have is that Spacemacs is an Emacs /clone/ of
|
|
|
|
vim. Spacemacs does not seek to completely mimic the behavior of vim
|
|
|
|
everywhere, only when editing. You should not expect every vim command to be
|
|
|
|
available, although many are. You cannot use Vimscript to configure Spacemacs,
|
|
|
|
but who likes Vimscript anyway? It is important to understand that Spacemacs is
|
|
|
|
an attempt to improve on both vim and Emacs using the superior modal editing of
|
|
|
|
vim and the nicer configuration language of Emacs.
|
|
|
|
|
|
|
|
* Basic orientation
|
2015-10-30 11:20:58 +00:00
|
|
|
** Terms
|
2015-05-10 20:07:09 +00:00
|
|
|
Spacemacs uses some different terminology than vim, which can cause confusion
|
|
|
|
for new users. This section attempts to clear up any confusion.
|
|
|
|
|
2015-10-30 11:20:58 +00:00
|
|
|
*** Modes vs. States
|
2015-05-10 20:07:09 +00:00
|
|
|
In vim you have various editing modes like =insert mode= and =visual mode= to
|
2015-07-04 11:46:15 +00:00
|
|
|
manipulate text. In Emacs, we have [[./DOCUMENTATION.org#states][states]]. These are equivalent to vim modes.
|
2015-06-09 05:31:29 +00:00
|
|
|
For example, =evil-insert-state= is the same as =insert-mode= in vim.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
A =minor-mode= in Emacs is like a feature that is activated. For example,
|
|
|
|
=aggressive-indent-mode= is a =minor-mode= that automatically indents code as you
|
2015-06-09 05:31:29 +00:00
|
|
|
type. It is important to know that there can be many =minor-modes= activated in a
|
|
|
|
buffer. Many Emacs packages work by providing a =minor-mode=. A =major-mode=
|
2015-05-10 20:07:09 +00:00
|
|
|
determines the editing behavior of Emacs in the current buffer. There is
|
2015-06-09 05:31:29 +00:00
|
|
|
generally a corresponding =major-mode= per filetype. An example of a =major-mode= is
|
|
|
|
=python-mode=, which provides python specific settings in python files. There is
|
|
|
|
only one =major-mode= per buffer.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-10-30 11:20:58 +00:00
|
|
|
*** Layers
|
2015-05-10 20:07:09 +00:00
|
|
|
Spacemacs has the concept of layers. Layers are similar to vim plugins. They
|
|
|
|
provide new features to use in Spacemacs. However, layers are often comprised of
|
|
|
|
several packages that integrate well with each other. For example, the =python=
|
|
|
|
layer includes support for auto-completion, documentation look-up, tests, and
|
|
|
|
much more by using several different packages. This keeps you from thinking
|
|
|
|
about what packages to install, and instead worry about what features you want.
|
2015-08-05 20:09:58 +00:00
|
|
|
More information on layers can be found in the [[./VIMUSERS.org#customization][customization]] section and in the
|
2015-10-30 11:20:58 +00:00
|
|
|
[[./DOCUMENTATION.org#configuration-layers][documentation]]. There is also a more in-depth guide on writing layers [[file:LAYERS.org][here]].
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-10-30 11:20:58 +00:00
|
|
|
*** Micro-states
|
2015-05-10 20:07:09 +00:00
|
|
|
Spacemacs provides a special functionality called micro-states. Micro-states
|
|
|
|
allow similar commands to be run in succession without repeatedly pressing the
|
2015-06-09 05:31:29 +00:00
|
|
|
~<Leader>~ key. Micro-states are usually triggered by using a keybinding with the
|
|
|
|
following pattern: ~<Leader> <group> .~ where group is the category the
|
|
|
|
micro-state falls under. When in a micro-state you will see documentation at the
|
|
|
|
bottom of your window. To exit a micro-state press ~q~.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-06-26 07:10:49 +00:00
|
|
|
#+CAPTION: Micro-state documentation window
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-06-26 07:10:49 +00:00
|
|
|
[[file:img/spacemacs-scale-micro-state.png]]
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-10-30 11:20:58 +00:00
|
|
|
** Keybinding conventions
|
2015-06-09 05:31:29 +00:00
|
|
|
Spacemacs uses ~SPC~ as its ~<Leader>~ key. This document will use ~SPC~ to refer to
|
|
|
|
the ~<Leader>~ key. All keybindings are mnemonic and are organized under the
|
|
|
|
~<Leader>~ key. For example, the keybindings for language-specific commands are
|
|
|
|
always under the ~SPC m~ prefix. A full list of conventions used in Spacemacs is
|
2015-07-04 11:46:15 +00:00
|
|
|
[[./CONVENTIONS.org][here]]. Note that all keybindings can be changed.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-08-26 12:07:46 +00:00
|
|
|
Spacemacs uses [[https://github.com/justbur/emacs-which-key][which-key]] to show available keybindings after a delay:
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-08-26 12:07:46 +00:00
|
|
|
#+CAPTION: Which-key window
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-08-26 12:07:46 +00:00
|
|
|
[[file:img/which-key.png]]
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-10-30 11:20:58 +00:00
|
|
|
** Running commands
|
2015-06-09 05:31:29 +00:00
|
|
|
Emacs commands can be run using ~SPC :~. This will pop up a buffer using [[https://github.com/emacs-helm/helm][Helm]]
|
|
|
|
which can be used to run any Emacs command. You can also run many ex commands
|
|
|
|
using ~:~, just like in vim.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-06-09 05:31:29 +00:00
|
|
|
Note: You can run Emacs interactive commands using ~:~, but you cannot run ex
|
|
|
|
commands using ~SPC :~.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-10-30 11:20:58 +00:00
|
|
|
** Buffer and window management
|
|
|
|
*** Buffers
|
2015-05-10 20:07:09 +00:00
|
|
|
Buffers in Emacs and vim are essentially the same. The keybindings for buffers
|
2015-06-10 11:24:17 +00:00
|
|
|
are located under the ~SPC b~ prefix.
|
2015-06-09 05:31:29 +00:00
|
|
|
|
2015-06-26 07:10:49 +00:00
|
|
|
| Keybinding | Function |
|
|
|
|
|---------------------------+------------------------------------------------------|
|
|
|
|
| ~SPC b b <buffer-name>~ | Create a buffer named =<buffer-name>=. |
|
|
|
|
| ~SPC b b~ | Search through open buffers and recent files. |
|
2015-06-09 05:31:29 +00:00
|
|
|
| ~SPC b n~ or ~:bnext~ | Switch to the next buffer. (See [[*Special%20buffers][Special buffers]]) |
|
|
|
|
| ~SPC b p~ or ~:bprevious~ | Switch to the previous buffer. (See [[*Special%20buffers][Special buffers]]) |
|
|
|
|
| ~SPC b d~ or ~:bdelete~ | Kill current buffer. |
|
2015-06-26 07:10:49 +00:00
|
|
|
| ~SPC b k~ | Search for a buffer to kill. |
|
|
|
|
| ~SPC b K~ | Kill all buffers except the current buffer. |
|
|
|
|
| ~SPC b .~ | Buffer micro-state. |
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-10-30 11:20:58 +00:00
|
|
|
**** Special buffers
|
2015-05-10 20:07:09 +00:00
|
|
|
By default Emacs creates a lot of buffers that most people will never need, like
|
|
|
|
=*Messages*=. Spacemacs automatically ignores these when using these
|
2015-06-26 07:10:49 +00:00
|
|
|
key bindings. More information can be found [[./DOCUMENTATION.org#special-buffers][here]].
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-10-30 11:20:58 +00:00
|
|
|
*** Windows
|
2015-05-10 20:07:09 +00:00
|
|
|
Windows are like splits in vim. They are useful for editing multiple files at
|
2015-06-10 11:24:17 +00:00
|
|
|
once. All window keybindings are under the ~SPC w~ prefix.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-06-26 07:10:49 +00:00
|
|
|
| Keybinding | Function |
|
|
|
|
|------------------------+--------------------------------------|
|
2015-06-09 05:31:29 +00:00
|
|
|
| ~SPC w v~ or ~:vsplit~ | Opens a vertical split on the right. |
|
|
|
|
| ~SPC w s~ or ~:split~ | Opens a horizontal split below. |
|
2015-06-26 07:10:49 +00:00
|
|
|
| ~SPC w h/j/k/l~ | Navigate among windows. |
|
|
|
|
| ~SPC w H/J/K/L~ | Move the current window. |
|
|
|
|
| ~SPC w .~ | Window micro-state. |
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-10-30 11:20:58 +00:00
|
|
|
** Files
|
2015-06-10 11:24:17 +00:00
|
|
|
All file commands in Spacemacs are available under the ~SPC f~ prefix.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-06-26 07:10:49 +00:00
|
|
|
| Keybinding | Function |
|
|
|
|
|-------------------+--------------------------------------------------------------|
|
|
|
|
| ~SPC f f~ | Opens a buffer to search for files in the current directory. |
|
|
|
|
| ~SPC f r~ | Opens a buffer to search through recently opened files. |
|
2015-06-09 05:31:29 +00:00
|
|
|
| ~SPC f s~ or ~:w~ | Save the current file. |
|
2015-06-26 07:10:49 +00:00
|
|
|
| ~:x~ | Save the current file and quit. |
|
|
|
|
| ~:e <file>~ | Open =<file>= |
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-10-30 11:20:58 +00:00
|
|
|
** The Help System
|
2015-06-09 05:31:29 +00:00
|
|
|
Emacs has an extensive help system. All keybindings under the ~SPC h d~ prefix
|
|
|
|
allow convenient access to the help system. The most important of these
|
2015-06-26 07:10:49 +00:00
|
|
|
keybindings are ~SPC h d f~ , ~SPC h d k~ , and ~SPC h d v~. There is also the
|
2015-06-09 05:31:29 +00:00
|
|
|
~SPC <f1>~ keybinding which allows you to search for documentation.
|
|
|
|
|
2015-06-26 07:10:49 +00:00
|
|
|
| Keybinding | Function |
|
|
|
|
|-------------+----------------------------------------------------------------------------------|
|
|
|
|
| ~SPC h d f~ | Prompts for a function and shows its documentation. |
|
|
|
|
| ~SPC h d k~ | Prompts for a keybinding and shows what it is bound to. |
|
|
|
|
| ~SPC h d v~ | Prompts for a variable and shows its documentation and current value. |
|
|
|
|
| ~SPC <f1>~ | Searches for a command, function, variable, or face and shows its documentation. |
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
Whenever, you see weird behavior or want to know what something does, these
|
|
|
|
functions are the first thing you should refer to.
|
|
|
|
|
2015-10-30 11:20:58 +00:00
|
|
|
** Exploring
|
2015-05-10 20:07:09 +00:00
|
|
|
There are a few ways to explore the functionality of Spacemacs. One is to read
|
|
|
|
the [[https://github.com/syl20bnr/spacemacs][source code]] on Github. You can begin to feel your way around Emacs Lisp and
|
|
|
|
how Spacemacs works this way. You can also use the following keybindings to
|
|
|
|
explore:
|
|
|
|
|
2015-06-26 07:10:49 +00:00
|
|
|
| Keybinding | Function |
|
|
|
|
|-------------+---------------------------------------------------------------|
|
2015-12-21 13:50:36 +00:00
|
|
|
| ~SPC h SPC~ | Lists all layers and allows you to view files from the layer. |
|
2015-06-26 07:10:49 +00:00
|
|
|
| ~SPC ?~ | Lists all keybindings. |
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
* Customization
|
|
|
|
** The .spacemacs file
|
|
|
|
When you first start spacemacs, you will be prompted to choose an editing style.
|
|
|
|
If you are reading this, you likely want to choose the vim style. A =.spacemacs=
|
|
|
|
file will be created with the appropriate style selected. Most trivial
|
|
|
|
configuration will go in this file.
|
|
|
|
|
2015-09-28 06:05:18 +00:00
|
|
|
There are four top-level function in the file: =dotspacemacs/layers=,
|
|
|
|
=dotspacemacs/init=, =dotspacemacs/user-init= and =dotspacemacs/user-config=.
|
|
|
|
The =dotspacemacs/layers= function exist only to enable and disable layers and
|
|
|
|
packages. The =dotspacemacs/init= function is run before anything else during
|
|
|
|
startup and contains Spacemacs settings. You will never need to touch this
|
|
|
|
function except to change default Spacemacs settings.
|
|
|
|
The =dotspacemacs/user-init= function is also run before anything else and
|
|
|
|
contains user specific configuration. The =dotspacemacs/user-config= function
|
|
|
|
is the one you will use the most. This is where you define any user configuration.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-06-26 07:10:49 +00:00
|
|
|
| Keybinding | Function |
|
|
|
|
|-------------+--------------------------------------------------------------------------|
|
|
|
|
| ~SPC f e d~ | Open your =.spacemacs= |
|
|
|
|
| ~SPC f e D~ | Update your =.spacemacs= manually using a diff with the default template |
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
** Emacs Lisp
|
|
|
|
This section introduces a few emacs lisp functions that are needed to configure
|
|
|
|
Spacemacs. For a more detailed look at the language, see [[http://learnxinyminutes.com/docs/elisp/][this]] link. If you
|
|
|
|
really want to learn everything there is about emacs lisp, use the info page
|
2015-06-09 05:31:29 +00:00
|
|
|
found at ~SPC h i elisp RET~ .
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
*** Variables
|
|
|
|
Setting variables is the most common way to customize the behavior of Spacemacs.
|
|
|
|
The syntax is simple:
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
|
|
|
(setq variable value) ; Syntax
|
2015-08-05 03:20:54 +00:00
|
|
|
;; Setting variables example
|
2015-06-26 07:10:49 +00:00
|
|
|
(setq variable1 t ; True
|
2015-05-10 20:07:09 +00:00
|
|
|
variable2 nil ; False
|
|
|
|
variable3 '("A" "list" "of" "things"))
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
*** Keybindings
|
|
|
|
Defining keybindings is something that almost everyone will want to do. The
|
|
|
|
built-in =define-key= function is the best way to do that.
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
|
|
|
(define-key map new-keybinding function) ; Syntax
|
|
|
|
;; Map H to go to the previous buffer in normal mode
|
|
|
|
(define-key evil-normal-state-map (kbd "H") 'spacemacs/previous-useful-buffer)
|
|
|
|
;; Mapping keybinding to another keybinding
|
|
|
|
(define-key evil-normal-state-map (kbd "H") (kbd "^")) ; H goes to beginning of the line
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
The map is the keymap you want to bind the key in. Most of the time you will use
|
|
|
|
=evil-<state-name>-state-map=. These correspond to different =evil-mode= states.
|
|
|
|
For example, using =evil-insert-state-map= maps the keybinding in insert mode.
|
|
|
|
|
2015-12-05 07:33:02 +00:00
|
|
|
To map ~<Leader>~ keybindings, use the =spacemacs/set-leader-keys= function.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
2015-12-05 07:33:02 +00:00
|
|
|
(spacemacs/set-leader-keys key function) ; Syntax
|
2015-05-10 20:07:09 +00:00
|
|
|
;; Map killing a buffer to <Leader> b c
|
2015-12-05 07:33:02 +00:00
|
|
|
(spacemacs/set-leader-keys "bc" 'kill-this-buffer)
|
|
|
|
;; Map opening a link to <Leader> o l only in org-mode (works for any major-mode)
|
2015-11-18 00:39:14 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'org-mode
|
2015-05-10 20:07:09 +00:00
|
|
|
"ol" 'org-open-at-point)
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
*** Functions
|
|
|
|
You may occasionally want to define a function to do a more complex
|
|
|
|
customization. The syntax is simple:
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
|
|
|
(defun func-name (arg1 arg2)
|
|
|
|
"docstring"
|
|
|
|
;; Body
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Calling a function
|
|
|
|
(func-name arg1 arg1)
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
Here is an example of a function that is useful in real life:
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
2015-06-26 07:10:49 +00:00
|
|
|
;; This snippet allows you to run clang-format before saving
|
|
|
|
;; given the current file as the correct filetype.
|
2015-08-05 03:20:54 +00:00
|
|
|
;; This relies on the c-c++ layer being enabled.
|
2015-06-26 07:10:49 +00:00
|
|
|
(defun clang-format-for-filetype ()
|
|
|
|
"Run clang-format if the current file has a file extensions
|
|
|
|
in the filetypes list."
|
|
|
|
(let ((filetypes '("c" "cpp")))
|
|
|
|
(when (member (file-name-extension (buffer-file-name)) filetypes)
|
|
|
|
(clang-format-buffer))))
|
|
|
|
|
|
|
|
;; See http://www.gnu.org/software/emacs/manual/html_node/emacs/Hooks.html for
|
|
|
|
;; what this line means
|
|
|
|
(add-hook 'before-save-hook 'clang-format-for-filetype)
|
2015-05-10 20:07:09 +00:00
|
|
|
#+end_src
|
|
|
|
|
|
|
|
** Activating a Layer
|
|
|
|
As said in the terms section, layers provide an easy way to add features.
|
|
|
|
Activating a layer is done in the =.spacemacs= file. In the file search for the
|
|
|
|
=dotspacemacs-configuration-layers= variable. By default, it should look like
|
|
|
|
this:
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
|
|
|
(defun dotspacemacs/layers ()
|
|
|
|
(setq-default
|
|
|
|
;; ...
|
|
|
|
dotspacemacs-configuration-layers '(;; auto-completion
|
|
|
|
;; better-defaults
|
|
|
|
emacs-lisp
|
|
|
|
;; (git :variables
|
|
|
|
;; git-gutter-use-fringe t)
|
|
|
|
;; markdown
|
|
|
|
;; org
|
2015-06-26 07:10:49 +00:00
|
|
|
;; syntax-checking
|
|
|
|
)))
|
2015-05-10 20:07:09 +00:00
|
|
|
#+end_src
|
|
|
|
|
|
|
|
You can uncomment these suggested layers by deleting the semi-colons for a nice
|
|
|
|
out-of-the-box experience. To add a layer, add its name to the list and restart
|
2015-06-26 07:10:49 +00:00
|
|
|
Emacs or press ~SPC f e R~ . To view all layers and their documentation use ~SPC
|
2015-12-21 13:50:36 +00:00
|
|
|
h SPC~.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
** Creating a Layer
|
2015-06-26 07:10:49 +00:00
|
|
|
To group configuration or when configuration doesn't fit well in your
|
|
|
|
=.spacemacs= file, you can create a configuration layer. Spacemacs provides a
|
|
|
|
builtin command to generate the layer boilerplate:
|
|
|
|
~SPC :configuration-layer/create-layer~. This generates a folder that looks like this:
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
#+BEGIN_EXAMPLE
|
|
|
|
[layer-name]
|
2015-08-11 03:20:30 +00:00
|
|
|
|__ [local]*
|
2015-05-10 20:07:09 +00:00
|
|
|
| |__ [example-mode-1]
|
|
|
|
| | ...
|
|
|
|
| |__ [example-mode-n]
|
|
|
|
|__ config.el*
|
|
|
|
|__ funcs.el*
|
|
|
|
|__ keybindings.el*
|
|
|
|
|__ packages.el
|
|
|
|
|
2015-08-11 03:20:30 +00:00
|
|
|
[] = directory
|
|
|
|
* = not created by the command
|
2015-05-10 20:07:09 +00:00
|
|
|
#+END_EXAMPLE
|
|
|
|
|
|
|
|
The =packages.el= file contains a list of packages that you can install in the
|
|
|
|
variable =<layer-name>-packages=. Any package that is available on the [[http:melpa.org][MELPA]]
|
2015-08-11 03:20:30 +00:00
|
|
|
repository can be added to the list. A list can also exclude packages using the
|
|
|
|
=:excluded t= property.
|
|
|
|
Each package requires a function to initialize it. The function /must/ be named
|
|
|
|
with this pattern: =<layer-name>/init-<package-name>=. This function contains
|
|
|
|
configuration for the package. There are also =pre/post-init= functions to
|
|
|
|
execute code before or after a package loads. It would look like this:
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
2015-08-11 03:20:30 +00:00
|
|
|
(setq layer-name-packages '(example-package
|
|
|
|
;; This layer uninstalls example-package-2
|
|
|
|
;; by setting the :excluded property to true (t)
|
|
|
|
(example-package-2 :excluded t)))
|
|
|
|
|
|
|
|
(defun layer-name/post-init-package ()
|
|
|
|
;; Add configuration to a package in another layer here
|
|
|
|
)
|
|
|
|
|
2015-05-10 20:07:09 +00:00
|
|
|
(defun layer-name/init-example-package ()
|
|
|
|
;; Configuration for example-package goes here
|
|
|
|
)
|
|
|
|
#+end_src
|
|
|
|
|
2015-08-11 03:20:30 +00:00
|
|
|
**Note**: Only one layer can have a =init= function for a package. If you want
|
|
|
|
to override the configuration of a package in another layer, use a
|
|
|
|
=<layer-name>/pre-init= function in addition to [[file:LAYERS.org#use-package-hooks][use-package hooks]].
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-08-11 03:20:30 +00:00
|
|
|
If a package is not available on MELPA, you must use a local package or a
|
|
|
|
package recipe. For more details see [[file:LAYERS.org#anatomy-of-a-layer][anatomy of a layer]].
|
2015-05-10 20:07:09 +00:00
|
|
|
|
2015-10-30 11:20:58 +00:00
|
|
|
Make sure you [[Activating a Layer][add]] your layer to your =.spacemacs= file and restart to
|
2015-05-10 20:07:09 +00:00
|
|
|
activate it.
|
2015-06-26 07:10:49 +00:00
|
|
|
|
2015-08-11 03:20:30 +00:00
|
|
|
A detailed description of the loading process and how layers work can be found in
|
|
|
|
[[file:LAYERS.org][LAYERS.org]].
|
2015-08-05 20:09:58 +00:00
|
|
|
|
2015-05-10 20:07:09 +00:00
|
|
|
** Installing a single package
|
|
|
|
Sometimes creating a layer is a bit overkill. Maybe you just want one package
|
|
|
|
and don't want to maintain a whole layer. Spacemacs provides a variable in the
|
2015-06-26 07:10:49 +00:00
|
|
|
=dotspacemacs/layers= function in =.spacemacs= called
|
2015-05-10 20:07:09 +00:00
|
|
|
=dotspacemacs-additional-packages=. Just add a package name to the list and it
|
|
|
|
will be installed when you restart. Loading the package is covered in the next
|
2015-10-30 11:20:58 +00:00
|
|
|
[[Loading packages][section]].
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
** Loading packages
|
|
|
|
Ever wonder how Spacemacs can load over a 100 packages in just a few seconds?
|
|
|
|
Such low loading times must require some kind of unreadable black magic that no
|
|
|
|
one can understand. Thanks to [[https://github.com/jwiegley/use-package][use-package]], this is not true. It is a package
|
|
|
|
that allows easy lazy-loading and configuration of packages. Here are the basics
|
|
|
|
to using it:
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
|
|
|
;; Basic form of use-package declaration. The :defer t tells use-package to
|
|
|
|
;; try to lazy load the package.
|
|
|
|
(use-package package-name
|
|
|
|
:defer t)
|
|
|
|
;; The :init section is run before the package loads The :config section is
|
|
|
|
;; run after the package loads
|
|
|
|
(use-package package-name
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
;; Change some variables
|
|
|
|
(setq variable1 t variable2 nil)
|
|
|
|
;; Define a function
|
2015-06-26 07:10:49 +00:00
|
|
|
(defun foo ()
|
|
|
|
(message "%s" "Hello, World!")))
|
2015-05-10 20:07:09 +00:00
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
;; Calling a function that is defined when the package loads
|
|
|
|
(function-defined-when-package-loads)))
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
This is just a very basic overview of =use-package=. There are many other ways
|
|
|
|
to control how a package loads using it that aren't covered here.
|
2015-06-26 07:10:49 +00:00
|
|
|
|
2015-05-10 20:07:09 +00:00
|
|
|
** Uninstalling a package
|
|
|
|
Spacemacs provides a variable in the =dotspacemacs/init= function in
|
2015-06-26 07:10:49 +00:00
|
|
|
=.spacemacs= called =dotspacemacs-excluded-packages=. Just add a package name to
|
|
|
|
the list and it will be uninstalled when you restart.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
** Common tweaks
|
|
|
|
This section is for things many will want to change. All of these settings go in
|
2015-09-28 06:05:18 +00:00
|
|
|
the =dotspacemacs/user-config= function in your =.spacemacs= unless otherwise noted.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
*** Changing the escape key
|
2015-06-26 07:10:49 +00:00
|
|
|
Spacemacs uses =[[https://github.com/syl20bnr/evil-escape][evil-escape]]= to
|
|
|
|
allow escaping from many =major-modes= with one keybinding. You can customize
|
2015-09-28 06:05:18 +00:00
|
|
|
the variable in your =dotspacemacs/user-config= like this:
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
2015-09-28 06:05:18 +00:00
|
|
|
(defun dotspacemacs/user-config ()
|
2015-05-10 20:07:09 +00:00
|
|
|
;; ...
|
|
|
|
;; Set escape keybinding to "jk"
|
|
|
|
(setq-default evil-escape-key-sequence "jk"))
|
|
|
|
#+end_src
|
|
|
|
|
2015-09-28 06:05:18 +00:00
|
|
|
More documentation is found in the =evil-escape= [[https://github.com/syl20bnr/evil-escape/blob/master/README.md][README]].
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
*** Changing the colorscheme
|
|
|
|
The =.spacemacs= file contains the =dotspacemacs-themes= variable in the
|
|
|
|
=dotspacemacs/init= function. This is a list of themes that can be cycled
|
2015-06-26 07:10:49 +00:00
|
|
|
through with the ~SPC T n~ keybinding. The first theme in the list is the one
|
|
|
|
that is loaded at startup. Here is an example:
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
|
|
|
(defun dotspacemacs/init
|
|
|
|
;; Darktooth theme is the default theme
|
|
|
|
;; Each theme is automatically installed.
|
|
|
|
;; Note that we drop the -theme from the package name.
|
|
|
|
;; Ex. darktooth-theme -> darktooth
|
|
|
|
(setq-default dotspacemacs-themes '(darktooth
|
|
|
|
soothe
|
|
|
|
gotham)))
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
2015-06-09 05:31:29 +00:00
|
|
|
All installed themes can be listed and chosen using the ~SPC T h~ keybinding.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
*** Nohlsearch
|
|
|
|
Spacemacs emulates the default vim behavior which highlights search results even
|
2015-06-26 07:10:49 +00:00
|
|
|
when you are not navigating between them. You can use ~SPC s c~ or ~:nohlsearch~
|
|
|
|
to disable search result highlighting.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
To disable the result highlighting when it is not needed anymore automatically,
|
2015-10-30 11:20:58 +00:00
|
|
|
you can [[Uninstalling a package][uninstall]] the =evil-search-highlight-persist= package.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
*** Sessions
|
|
|
|
Spacemacs does not automatically restore your windows and buffers when you
|
2016-01-04 08:27:33 +00:00
|
|
|
reopen it. If you use vim sessions regularly you may want to set
|
|
|
|
=dotspacemacs-auto-resume-layouts= to =t= in your =.spacemacs=.
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
*** Navigating using visual lines
|
|
|
|
Spacemacs uses the vim default of navigating by actual lines, even if they are
|
2015-06-26 07:10:49 +00:00
|
|
|
wrapped. If you want ~j~ and ~k~ to behave like ~g j~ and ~g k~, add this to
|
|
|
|
your =.spacemacs=:
|
2015-05-10 20:07:09 +00:00
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
2015-06-26 07:10:49 +00:00
|
|
|
(define-key evil-normal-state-map (kbd "j") 'evil-next-visual-line)
|
|
|
|
(define-key evil-normal-state-map (kbd "k") 'evil-previous-visual-line)
|
2015-05-10 20:07:09 +00:00
|
|
|
#+end_src
|
|
|
|
|
|
|
|
* Other useful links
|
|
|
|
- [[https://www.gnu.org/software/emacs/manual/emacs.html][Emacs Manual]]
|
2015-07-04 11:46:15 +00:00
|
|
|
- [[file:DOCUMENTATION.org][Spacemacs Documentation]]
|
2015-05-10 20:07:09 +00:00
|
|
|
- [[http://ian.mccowan.space/2015/04/07/Spacemacs/][Spacemacs: A Vimmer's Emacs Prerequisites]]
|
2015-06-26 07:10:49 +00:00
|
|
|
- Note: The article refers to ~SPC b s~ as the keybinding to switch buffers.
|
|
|
|
It is ~SPC b b~
|
2015-05-10 20:07:09 +00:00
|
|
|
- [[http://thume.ca/howto/2015/03/07/configuring-spacemacs-a-tutorial/][Configuring Spacemacs: A Tutorial]]
|
|
|
|
- [[http://juanjoalvarez.net/es/detail/2014/sep/19/vim-emacsevil-chaotic-migration-guide/][From Vim to Emacs+Evil chaotic migration guide]]
|