31 | | === snippetsEmu === |
32 | | Development takes place on [http://code.google.com/p/snippetsemu Google Code], where the subversion repository includes predefined snippets for django/python/etc. |
33 | | |
34 | | [http://www.vim.org/scripts/script.php?script_id=1318 SnippetsEmu] allows one to define abbreviations which can be expanded into larger blocks of text. The abbreviations can also contain place markers which can be 'jumped to' in a similar manner to the macros defined in TextMate on OS X. |
35 | | |
36 | | One can add specific abbreviations for models or templates based on file contents. Adding the following line to your ~/.vim/after/ftplugin/python.vim file (create it if you don't have it) will allow you to define abbreviations just for models (use the file \Program Files\vim\vimfiles\after\ftplugin\python.vim under Windows): |
37 | | {{{ |
38 | | if getline(1) =~ 'from django.db import models' |
39 | | "Your abbreviations here |
40 | | endif |
41 | | }}} |
42 | | |
43 | | The following is an example collection of Django specific abbreviations for use with the plugin. More examples can be found in the [http://snippetsemu.googlecode.com/svn/trunk/after/ftplugin/ subversion repository]. Please email the author with any of your own additions (f dot ingram dot lists at gmail dot com): |
44 | | |
45 | | Models: |
46 | | {{{ |
47 | | Snippet addmodel class <{}>(models.Model):<CR><><CR><CR>def __unicode__(self):<CR>return "%s" % (<{}>,) |
48 | | Snippet mcf models.CharField(max_length=<{}>)<CR><{}> |
49 | | Snippet mff models.FileField(upload_to=<{}>)<CR><{}> |
50 | | Snippet mfpf models.FilePathField(path=<{}>, match="<{}>", recursive=<False>)<CR><{}> |
51 | | Snippet mfloat models.FloatField(max_digits=<{}>, decimal_places=<{}>)<CR><{}> |
52 | | Snippet mfk models.ForeignKey(<{}>)<CR><{}> |
53 | | Snippet m2m models.ManyToManyField(<{}>)<CR><{}> |
54 | | Snippet o2o models.OneToOneField(<{}>)<CR><{}> |
55 | | }}} |
56 | | |
57 | | Templates: |
58 | | |
59 | | {{{ |
60 | | Snippet fore {% for <{entry}> in <{list}> %}<CR>{{ <{entry}>.<{}> }}<CR><{}>{% endfor %}<CR><{}> |
61 | | }}} |
62 | | |
63 | | snippetsEmu for '''urls.py''' and '''views.py''' files can be found on the attachment section. To use this snippets, copy them into ''~/.vim/after/ftplugin/'' directory |
64 | | |
65 | | |
66 | | === !SnipMate.vim === |
67 | | |
68 | | [http://www.vim.org/scripts/script.php?script_id=2540 SnipMate] is another plugin that adds TextMate-style snippets for Vim. The [http://github.com/robhudson/snipmate_for_django/tree/master snipmate_for_django] Git repository, by Rob Hudson, contains many of the TextMate snippets converted to !SnipMate. |
| 26 | === YouCompleteMe === |
| 27 | [https://github.com/Valloric/YouCompleteMe YouCompleteMe] is a fast, as-you-type, fuzzy-search code completion engine for Vim, it provide a [http://jedi.jedidjah.ch/en/latest/ Jedi]-based completion engine for Python. |
| 28 | |
| 29 | Lines below are recommended settings for YCM: |
| 30 | {{{ |
| 31 | let g:ycm_collect_identifiers_from_tags_files = 1 " Let YCM read tags from Ctags file |
| 32 | let g:ycm_use_ultisnips_completer = 1 " Default 1, just ensure |
| 33 | let g:ycm_seed_identifiers_with_syntax = 1 " Completion for programming language's keyword |
| 34 | let g:ycm_complete_in_comments = 1 " Completion in comments |
| 35 | let g:ycm_complete_in_strings = 1 " Completion in string |
| 36 | }}} |
| 37 | |
| 38 | === Ultisnips.vim === |
| 39 | |
| 40 | [https://github.com/SirVer/ultisnips UltiSnips] is the ultimate solution for snippets in Vim, it is written in python and works perfectly with [https://github.com/Valloric/YouCompleteMe YouCompleteMe]. |
| 41 | |
| 42 | Lines below are recommended settings for Ultisnips to be working with YouCompleteMe: |
| 43 | |
| 44 | {{{ |
| 45 | let g:UltiSnipsExpandTrigger = "<c-j>" |
| 46 | let g:UltiSnipsJumpForwardTrigger = "<c-j>" |
| 47 | let g:UltiSnipsJumpBackwardTrigger = "<c-p>" |
| 48 | let g:UltiSnipsListSnippets = "<c-k>" "List possible snippets based on current file |
| 49 | }}} |