YASnippet Documentation

repository·master·Indexed 25 days ago

https://github.com/joaotavora/yasnippet

A template system for Emacs that expands abbreviations into function templates. It supports various programming languages, is compatible with TextMate snippet syntax, and can be installed via Git, package-install, el-get, or MELPA.

Tokens
609
Snippets
3
Records
5
Agent score
34%

What's inside YASnippet

  1. Install YASnippet via package-install, el-get, or MELPA

    master

    YASnippet can be installed using standard Emacs package managers:

    • package-install: Use M-x list-packages to find and install it from GNU ELPA, GNU-devel ELPA, or MELPA.
    • el-get: Use el-get to fetch the most recent version.
    • MELPA: Available via the MELPA repository.
  2. Install YASnippet manually from Git

    master

    To install YASnippet manually, clone the repository into your Emacs plugins directory and update your .emacs configuration to include the path, require the package, and enable global mode.

    $ cd ~/.emacs.d/plugins
    $ git clone --recursive https://github.com/joaotavora/yasnippet
    (add-to-list 'load-path
                      "~/.emacs.d/plugins/yasnippet")
    (require 'yasnippet)
    (yas-global-mode 1)
  3. Enable YASnippet on a per-buffer basis using yas-minor-mode

    master

    If you do not want YASnippet enabled globally, avoid calling yas-global-mode. Instead, call yas-reload-all to load the snippet tables and then add yas-minor-mode to the hooks of specific major-modes where you want it active.

    (yas-reload-all)
    (add-hook 'prog-mode-hook #'yas-minor-mode)
  4. Configure snippet directories with yas-snippet-dirs

    master

    YASnippet does not bundle snippets by default. To use external snippet collections, point the yas-snippet-dirs variable to the relevant directories and then reload the snippets.

    (setq yas-snippet-dirs
              '("`~/.emacs.d/snippets"                 ;; personal snippets
                "/path/to/some/collection/"           ;; foo-mode and bar-mode snippet collection
                "/path/to/yasnippet/yasmate/snippets" ;; the yasmate collection
                ))
    
    (yas-global-mode 1) ;; or M-x yas-reload-all if you've started YASnippet already.