You are viewing the documentation for the develop branch. The documentation for the release version is here .

Table of Contents

Templates layer

Table of ContentsClose

1. Description

This layer provides templates to Spacemacs. A template consists of text that is automatically inserted into a new file when it is opened. This is done via yatemplate, which leverages yasnippet.

1.1. Features:

  • Auto-insert snippets when creating specific new files.

2. Install

To use this configuration layer, add it to your ~/.spacemacs. You will need to add templates to the existing dotspacemacs-configuration-layers list in this file.

3. Configuration

Drop your templates in ~/.emacs.d/private/templates.

You can also specify a different location with templates-private-directory:

(setq-default dotspacemacs-configuration-layers
  '((templates :variables templates-private-directory "~/.spacemacs.d/templates")))

Each file in this directory must be of the form XXX:regexp where regexp is a regular expression that will be matched against filenames. The prefix XXX can be used to enforce an ordering (templates that come first will have priority). It is not part of the final regexp. Therefore, more specific templates should come first. For example,


See the yatemplate documentation for specifics. Full yasnippet syntax is supported, so consult the yasnippet documentation for details.

3.1. Default insertions

Note that Emacs ships with some default templates. If these are not to your liking, set the layer variable templates-use-default-templates to nil.

(setq-default dotspacemacs-configuration-layers
  '((templates :variables templates-use-default-templates nil)))

3.2. Querying

To disable the automatic querying each time a new file is opened, set auto-insert-query to nil.

(setq auto-insert-query nil)

Author: root

Created: 2022-05-24 Tue 11:51