1

I'm running Vim 8.0.124 and I've installed the vim-snipmate plugin to use in my Python and Django development. I followed the instructions by creating a .vimrc file that contains the following:

# ~/.vimrc
set nocompatible        " Required by Vundle
filetype off            " Required by Vundle

" Begin Vundle settings ==========================================================
"
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'VundleVim/Vundle.vim'
Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'tomtom/tlib_vim'
Plugin 'garbas/vim-snipmate'
# Optional
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'

call vundle#end()
filetype plugin indent on
"
" End Vundle settings ==========================================================

" SnipMate
autocmd FileType python set ft=python.django
autocmd FileType html set ft=htmldjango.html

" UltiSnips
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
let g:UltiSnipsEditSplit="vertical"

Installing vim-snipmate includes the creation of these four files:

~/.vim/bundle/vim-snippets/snippets/django.snippets
~/.vim/bundle/vim-snippets/snippets/htmldjango.snippets
~/.vim/bundle/vim-snippets/UltiSnips/django.snippets
~/.vim/bundle/vim-snippets/UltiSnips/htmldjango.snippets

I have two questions. First, why are the UltiSnip Django snippets not working? The snippets in snippets/django.snippets work but those in the UltiSnips django.snippets file don't. If I open a file test.py and type "fdate" where fdate should expand into a Django DateField, nothing happens (other than a tab is entered). Initially, when the UltiSnips weren't working, I went to its Github page and read the instructions which seemed to indicate I should add the SirVer plugin so I did. Even then, then don't seem to work. I should add that what you see above is my entire .vimrc file. Also, I created a completely new ~/.vim directory which only contains the Vundle and vim-snipmate bundles so there shouldn't be any other conflicts.

My second less important question is, when I view any of these snippet files, most of the lines are folded. Is there any way I can configure Vim so that when I open any of these .snippet files, all the folds will be open? They would be easier to search that way.

Jim
  • 13,430
  • 26
  • 104
  • 155

2 Answers2

0

Did you try with ":setfiletype htmldjango" ? or ":selfiletype django" (https://www.vim.org/scripts/script.php?script_id=1487)

2001
  • 1
  • 3
0

Take a look in the docs, especially under section 4.1.1 How snippets are loaded UltiSnips-how-snippets-are-loaded

I had similar issue, I've created separate directory for snippets, at $HOME/UltiSnips. There I've created directory python, where I've moved files python.snippet and django.snippet. Similarly, you may create directories for another languages and use snippets for another frameworks.

From the docs:

UltiSnips iterates over the snippet definition directories looking for files with names of the following patterns: ft.snippets, ft_.snippets, or ft/, where "ft" is the 'filetype' of the current document and "*" is a shell-like wildcard matching any string including the empty string.

Arthur Sult
  • 676
  • 7
  • 10