Contents
Yasnippet is a template system for emacs. It allows you to type a abbrevation and automatically expand the abbreviation into function templates.
Bundled language templates includes: C, C++, C#, Perl, Python, Ruby, SQL, LaTeX, HTML, CSS and more.
Yasnippet system is inspired from TextMate's template system. You can use a tool to import any TextMate template you have to Yasnippet. It is a re-design and re-write of my original extension smart-snippet. It is much cleaner and more powerful than smart-snippet.
Watch the demo at YouTube (download a higher resolution version: yasnippet.avi).
There are two archives of YASnippet. One is a single file compiled “bundle”, and the other is normal. If all you need is to use the builtin templates, download the bundle one. If you want to add your own templates, download the normal one.
That's it. Now open any one of your language file, you'll see a menu YASnippet. you can pull the menu to insert a template. Or, you can type the pre-defined abbrev and press TAB to expand it.
To have emacs load YASnippet automatically when it starts, put the following in your ~/.emacs file:
(add-to-list 'load-path "~/.emacs.d/plugins") (require 'yasnippet-bundle)
For full install of the normal archive, just download and unpack the latest yasnippet-x.y.z.tar.bz2. You'll get a directory named yasnippet, put it in your ~/.emacs.d/plugins and add the following in your .emacs file:
(add-to-list 'load-path "~/.emacs.d/plugins") (require 'yasnippet) ;; not yasnippet-bundle (yas/initialize) (yas/load-directory "~/.emacs.d/plugins/yasnippet/snippets")
Please refer to the documentation for full customization, or use the customization group.
Since version 0.6, YASnippet contains more functionality. You don't need to know all of it to use it sucessfully, but you it can improve your snippeting experience.
Hence this section has been split into separate documents:
Describes ways to organize your snippets in the hard disk, or not organize them at all and just use plain old elisp.
Also explains how to use the YASnippet menu to explore and learn new snippets.
Maybe, you'll want some snippets to be expanded in a particular mode, or only under certain conditions. Also you might want snippets to wrap themselves around a region of selected text, use a direct keybinding, control indenting, etc...
Describes the YASnippet definition syntax, which is similar, but not equivalent to Textmate's. Includes a section about converting Textmate snippets.
From version 0.6 onwards, there is a customization group that you can access with:
M-x customize-group RET yasnippet RET
Each customization variable affects how some part of YASnippet works, for example automatic snippet indentation, what prompting method to use, whether to expand snippets inside snippets, etc...
Inside the customization group, each variable is reasonably documented to explain what it does.
Thank you very much for using YASnippet!