2014-08-29 04:20:57 -04:00
|
|
|
snipMate & UltiSnip Snippets
|
2013-03-17 15:13:47 -04:00
|
|
|
============================
|
2011-06-20 18:49:54 -04:00
|
|
|
|
2012-11-29 05:33:15 -05:00
|
|
|
This repository contains snippets files for various programming languages.
|
|
|
|
|
2013-04-23 08:57:09 -04:00
|
|
|
It is community-maintained and many people have contributed snippet files and
|
|
|
|
other improvements already.
|
2012-12-07 03:55:14 -05:00
|
|
|
|
2013-03-17 15:13:47 -04:00
|
|
|
Contents
|
2014-03-04 03:26:10 -05:00
|
|
|
--------
|
2012-12-07 04:02:28 -05:00
|
|
|
|
2014-08-29 04:20:57 -04:00
|
|
|
- `snippets/*`: snippets using snipMate format
|
2014-03-04 03:26:10 -05:00
|
|
|
- `UltiSnips/*`: snippets using UltiSnips format
|
2012-12-07 04:02:28 -05:00
|
|
|
|
2014-02-07 06:58:05 -05:00
|
|
|
Snippet engines supporting vim-snippets
|
2014-03-04 03:26:10 -05:00
|
|
|
----------------------------------------
|
2012-12-07 03:55:14 -05:00
|
|
|
|
2013-03-17 15:13:47 -04:00
|
|
|
There are different forks of snippet engines which allow the user to insert
|
2014-02-07 06:58:05 -05:00
|
|
|
snippets by typing the name of a snippet hitting the expansion mapping.
|
2012-12-07 03:55:14 -05:00
|
|
|
|
2014-03-04 03:26:10 -05:00
|
|
|
- [github.com/SirVer/ultisnips](https://github.com/SirVer/ultisnips):
|
|
|
|
python, supports all snippets in this repo.
|
|
|
|
- [github.com/garbas/vim-snipmate](https://github.com/garbas/vim-snipmate):
|
|
|
|
VimL, snipmate-snippets, engine sometimes behaves strange. Supports
|
|
|
|
snippets/*
|
|
|
|
- [github.com/Shougo/neosnippet](https://github.com/Shougo/neosnippet.vim):
|
|
|
|
VimL, supports snippets/* with some configuration.
|
|
|
|
- [github.com/drmingdrmer/xptemplate](https://github.com/drmingdrmer/xptemplate):
|
|
|
|
Totally different syntax, does not read snippets contained in this file, but
|
|
|
|
it is also very powerful. It does not support vim-snippets (just listing it
|
2014-08-29 04:20:57 -04:00
|
|
|
here for completeness)
|
|
|
|
|
2014-03-04 03:26:10 -05:00
|
|
|
There tries to be a more comprehensive list (which still is incomplete) here:
|
|
|
|
http://vim-wiki.mawercer.de/wiki/topic/text-snippets-skeletons-templates.html
|
|
|
|
|
|
|
|
UltiSnips has additional features such as high speed, nesting snippets,
|
|
|
|
expanding snippets in snippets and offers powerful transformations on text in
|
|
|
|
snippets (like visual selections or placeholder texts).
|
|
|
|
|
|
|
|
Which one to use? If you have python give
|
|
|
|
[SirVer/ultisnips](https://github.com/SirVer/ultisnips) a try because its fast
|
|
|
|
and has the most features.
|
2013-03-17 15:13:47 -04:00
|
|
|
|
|
|
|
If you have VimL only (vim without python support) your best option is using
|
2014-03-04 03:26:10 -05:00
|
|
|
[garbas/vim-snipmate](https://github.com/garbas/vim-snipmate) and cope with the
|
|
|
|
minor bugs found in the engine.
|
2013-03-17 15:13:47 -04:00
|
|
|
|
2014-08-29 04:20:57 -04:00
|
|
|
Q: Should "snipMate be deprecated in favour of UltiSnips"?
|
2013-06-22 20:30:26 -04:00
|
|
|
|
2014-08-29 04:20:57 -04:00
|
|
|
A: No, because snipMate is VimL, and UltiSnips requires Python.
|
2014-05-05 11:44:05 -04:00
|
|
|
Some people want to use snippets without having to install Vim with Python
|
2014-08-29 04:20:57 -04:00
|
|
|
support. Yes - this sucks.
|
2014-05-05 11:44:05 -04:00
|
|
|
|
|
|
|
One solution would be: Use snippets if they are good enough, but allow overriding them
|
|
|
|
in UltiSnips. This would avoid most duplication while still serving most users.
|
2014-08-29 04:20:57 -04:00
|
|
|
AFAIK there is a nested-placeholder branch for snipMate too. snipMate is still
|
2014-05-05 11:44:05 -04:00
|
|
|
improved by Adnan Zafar. So maybe time is not ready to make a final decision yet.
|
|
|
|
|
2014-05-06 07:09:47 -04:00
|
|
|
[github issue/discussion](https://github.com/honza/vim-snippets/issues/363)
|
2014-05-06 06:22:24 -04:00
|
|
|
|
2014-02-06 12:24:54 -05:00
|
|
|
Installation
|
2014-03-04 03:26:10 -05:00
|
|
|
------------
|
|
|
|
|
2014-02-06 12:24:54 -05:00
|
|
|
First be aware that there are many options, see "Snippet engines" above.
|
|
|
|
Second be aware than there are [tons of plugin managers](http://vim-wiki.mawercer.de/wiki/topic/vim%20plugin%20managment.html)
|
|
|
|
which is why Marc Weber thinks that it doesn't make sense to repeat the same
|
|
|
|
repetitive information everywhere.
|
|
|
|
|
|
|
|
*Recommended way:*
|
2014-08-26 13:35:30 -04:00
|
|
|
[vim-addon-manager](https://github.com/MarcWeber/vim-addon-manager) (because Marc Weber wrote it for exactly
|
2014-08-29 04:20:57 -04:00
|
|
|
this reason, it supports simple dependency management). E.g. you're done by this
|
|
|
|
line in your `.vimrc`:
|
2014-02-06 12:24:54 -05:00
|
|
|
|
2014-08-29 04:20:57 -04:00
|
|
|
```vim
|
2014-02-06 12:24:54 -05:00
|
|
|
" assuming you want to use snipmate snippet engine
|
|
|
|
ActivateAddons vim-snippets snipmate
|
|
|
|
```
|
|
|
|
|
|
|
|
[vim-pi](https://bitbucket.org/vimcommunity/vim-pi/issue/90/we-really-need-a-web-interface)
|
|
|
|
Is the place to discuss plugin managers and repository resources.
|
|
|
|
|
2014-08-29 04:20:57 -04:00
|
|
|
About how to install snipMate see [snipmate@garbas](https://github.com/garbas/vim-snipmate)
|
2014-02-06 12:29:28 -05:00
|
|
|
|
|
|
|
(Bundle, Pathogen, git clone - keywords to make people find this link by ctrl-f search)
|
2014-08-29 04:20:57 -04:00
|
|
|
I know that I should be reading the docs of the snippet engine, just let me copy paste into my `.vimrc`:
|
2014-05-01 16:05:39 -04:00
|
|
|
[See this pull request](https://github.com/honza/vim-snippets/pull/307/files).
|
2014-02-06 12:24:54 -05:00
|
|
|
|
2014-02-07 06:58:05 -05:00
|
|
|
TROUBLE
|
|
|
|
=======
|
2014-08-29 04:20:57 -04:00
|
|
|
|
|
|
|
If you still have trouble getting this to work create a GitHub ticket, ask on
|
|
|
|
IRC or the mailing list.
|
2014-02-07 06:58:05 -05:00
|
|
|
|
2013-06-22 20:30:26 -04:00
|
|
|
Policies / for contributors
|
2014-03-04 03:26:10 -05:00
|
|
|
---------------------------
|
|
|
|
|
2013-06-23 12:26:47 -04:00
|
|
|
Some snippets are useful for almost all languages, so let's try to have the same
|
|
|
|
triggers for them:
|
2013-06-22 20:30:26 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
if : if without else
|
|
|
|
ife: if $1 else $2
|
|
|
|
eif : else if ($1) { .. }
|
|
|
|
el : else ..
|
2013-08-08 05:24:27 -04:00
|
|
|
wh : while (cond) ...
|
2013-06-22 20:30:26 -04:00
|
|
|
```
|
|
|
|
|
2014-08-29 04:20:57 -04:00
|
|
|
Don't add useless placeholder default texts like:
|
|
|
|
|
2013-06-22 20:30:26 -04:00
|
|
|
```
|
2013-06-23 12:26:47 -04:00
|
|
|
if (${1:condition}){
|
2013-06-22 20:30:26 -04:00
|
|
|
${2:some code here}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
instead use:
|
|
|
|
|
|
|
|
```
|
2013-06-23 12:26:47 -04:00
|
|
|
if (${1}){
|
2013-06-22 20:30:26 -04:00
|
|
|
${2}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2014-08-29 04:20:57 -04:00
|
|
|
Exception: Functions which are used less often, such as Vim's `matchall()`, `matchstr()`
|
2013-06-22 20:30:26 -04:00
|
|
|
functions which case hints may be helpful to remember order. In the VimL case
|
|
|
|
get vim-dev plugin which has function completion
|
|
|
|
|
|
|
|
Thus for conditions (while, if ..) and block bodies just use ${N} - Thanks
|
|
|
|
|
2013-06-23 07:31:33 -04:00
|
|
|
Open questions:
|
|
|
|
What about one line if ee then .. else .. vs if \n .. then \n ... \n else \n .. ?
|
2013-08-08 05:24:27 -04:00
|
|
|
Which additional policies to add?
|
2013-06-23 07:31:33 -04:00
|
|
|
Discuss at: https://github.com/honza/vim-snippets/issues/230
|
|
|
|
|
2014-05-06 07:13:44 -04:00
|
|
|
*folding markers*:
|
|
|
|
Until further work is done on `vim-snipmate`, please don't add folding markers
|
|
|
|
into snippets. `vim-snipmate` has some comments about how to patch all snippets
|
|
|
|
on the fly adding those.
|
|
|
|
|
|
|
|
Currently all snippets from UltiSnips have been put into UltiSnips - some work
|
|
|
|
on merging should be done (dropping duplicates etc). Also see engines section above.
|
2013-06-23 07:31:33 -04:00
|
|
|
|
2013-04-03 22:45:37 -04:00
|
|
|
Related repositories
|
2014-03-04 03:26:10 -05:00
|
|
|
--------------------
|
2014-08-29 04:20:57 -04:00
|
|
|
|
2013-04-03 22:55:39 -04:00
|
|
|
We also encourage people to maintain sets of snippets for particular use cases
|
|
|
|
so that all users can benefit from them. People can list their snippet repositories here:
|
2013-04-03 22:45:37 -04:00
|
|
|
|
2014-08-29 04:20:57 -04:00
|
|
|
* https://github.com/rbonvall/snipmate-snippets-bib (snippets for BibTeX files)
|
|
|
|
* https://github.com/sudar/vim-arduino-snippets (snippets for Arduino files)
|
|
|
|
* https://github.com/zedr/zope-snipmate-bundle.git (snippets for Python, TAL and ZCML)
|
|
|
|
* https://github.com/bonsaiben/bootstrap-snippets (snippets for Twitter Bootstrap markup, in HTML and Haml)
|
2013-04-03 22:55:39 -04:00
|
|
|
|
2014-08-29 04:20:57 -04:00
|
|
|
Installation using VAM: https://github.com/MarcWeber/vim-addon-manager
|
2013-04-03 22:45:37 -04:00
|
|
|
|
2013-06-20 06:57:09 -04:00
|
|
|
Future - ideas - examples
|
2014-03-04 03:26:10 -05:00
|
|
|
-------------------------
|
|
|
|
|
2013-06-20 06:57:09 -04:00
|
|
|
[overview snippet engines](http://vim-wiki.mawercer.de/wiki/topic/text-snippets-skeletons-templates.html)
|
|
|
|
If you have ideas you can add them to that list of "snippet engine features by example".
|
|
|
|
|
2013-03-17 15:13:47 -04:00
|
|
|
Historical notes
|
2014-03-04 03:26:10 -05:00
|
|
|
----------------
|
2011-06-20 18:49:54 -04:00
|
|
|
|
|
|
|
[vim-snipmate][1] was originally started by [Michael Sanders][2] who has now
|
|
|
|
unfortunately abandoned the project. [Rok Garbas][3] is now maintaining a
|
|
|
|
[fork][4] of the project in hopes of improving the existing code base.
|
|
|
|
|
2013-04-29 14:15:42 -04:00
|
|
|
Versions / dialects / ..
|
|
|
|
========================
|
2014-08-29 04:20:57 -04:00
|
|
|
|
2013-04-29 14:15:42 -04:00
|
|
|
There are some issues, such as newer language versions may require other
|
|
|
|
snippets than older. If this exists we currently recommend doing this:
|
|
|
|
|
2014-08-29 04:20:57 -04:00
|
|
|
* add snippets/ruby.snippets (common snippets)
|
|
|
|
* add snippets/ruby-1.8.snippets (1.8 only)
|
|
|
|
* add snippets/ruby-1.9.snippets (1.9 only)
|
2013-04-29 14:15:42 -04:00
|
|
|
|
2014-08-29 04:20:57 -04:00
|
|
|
then configure https://github.com/garbas/vim-snipmate this way:
|
2013-04-29 14:15:42 -04:00
|
|
|
|
2013-06-01 03:13:23 -04:00
|
|
|
```vim
|
|
|
|
let g:snipMate = {}
|
|
|
|
let g:snipMate.scope_aliases = {}
|
|
|
|
let g:snipMate.scope_aliases['ruby'] = 'ruby,ruby-rails,ruby-1.9'
|
|
|
|
```
|
2013-04-29 14:15:42 -04:00
|
|
|
|
|
|
|
If it happens that you work on a project requiring ruby-1.8 snippets instead,
|
2014-08-29 04:20:57 -04:00
|
|
|
consider using `vim-addon-local-vimrc` and override the filetypes.
|
2012-11-29 05:33:15 -05:00
|
|
|
|
2013-04-29 16:40:16 -04:00
|
|
|
Well - of course it may not make sense to create a new file for each
|
|
|
|
ruby-library-version triplet. Sometimes postfixing a name such as
|
|
|
|
|
2014-08-29 04:20:57 -04:00
|
|
|
```
|
|
|
|
migrate_lib_20_down
|
|
|
|
migrate_lib_20_up
|
|
|
|
```
|
2013-04-29 16:40:16 -04:00
|
|
|
|
|
|
|
will do it then if syntax has changed.
|
|
|
|
|
2011-06-21 07:07:45 -04:00
|
|
|
Language maintainers
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
No one can really be proficient in all programming languages. If you would like
|
|
|
|
to maintain snippets for a language, please get in touch.
|
|
|
|
|
2014-03-04 03:26:10 -05:00
|
|
|
Notes: People are interested in snippets - and their interest may wane again.
|
|
|
|
This list is kept up-to-date on a best effort basis.
|
2013-04-29 14:15:42 -04:00
|
|
|
|
2011-06-21 07:07:45 -04:00
|
|
|
* Python - [honza](http://github.com/honza)
|
|
|
|
* Javascript - [honza](http://github.com/honza)
|
|
|
|
* HTML Django - [honza](http://github.com/honza)
|
|
|
|
* Markdown - [honza](http://github.com/honza)
|
2011-06-21 10:31:03 -04:00
|
|
|
* Ruby - [taq](http://github.com/taq)
|
2012-07-24 15:06:32 -04:00
|
|
|
* PHP - [chrisyue](http://github.com/chrisyue)
|
2013-04-23 08:57:09 -04:00
|
|
|
* Scala - [gorodinskiy](https://github.com/gorodinskiy)
|
2013-06-07 13:43:24 -04:00
|
|
|
* Falcon - [steveno](https://github.com/steveno)
|
2013-06-23 12:27:35 -04:00
|
|
|
* Elixir - [iurifq](https://github.com/iurifq)
|
2011-06-21 07:07:45 -04:00
|
|
|
|
2011-06-20 18:49:54 -04:00
|
|
|
License
|
|
|
|
-------
|
|
|
|
|
|
|
|
Just as the original snipMate plugin, all the snippets are licensed under the
|
|
|
|
terms of the MIT license.
|
|
|
|
|
|
|
|
[1]: http://github.com/garbas/vim-snipmate
|
|
|
|
[2]: http://github.com/msanders
|
|
|
|
[3]: http://github.com/garbas
|
|
|
|
[4]: http://github.com/garbas/vim-snipmate
|
2013-03-17 15:13:47 -04:00
|
|
|
[7]: http://github.com/SirVer/ultisnips
|