Copying this question over from https://stackoverflow.com/q/42474604/262108I recently started working with django templates and was wondering whether there are any autocompletion plugins for template directives like {% block|if|... %}etc that do not involve a snippets library.I specifically do not want a snippet plugin because I find them quite distracting when editing code. Most snippet plugins would require digging thru' the docs and to figure out configuration to disable (rather than enable) snippets.I am thinking something along the lines of auto-pairs and xmledit which does something like (assuming | is the cursor):{% block ... %}|   <-- recognize I entered a %}complete it to:{% block ... %}    |   <------- place the cursor here{% endblock %}
vim plugin to autocomplete blocks in django templates but *not* a generic snippets plugin?
autocompletion;plugin system
The principle:listen for }, not %}analyse the context to decide what to return from a :h :map-<expr>the mapping shall be buffer local in order to avoid side-effects with other filetypes (:h :map-<buffer>)The movements returned shall be in double-quoted string and escaped with a back-slash (otherwise, you'll see the text <up><c-f> inserted)I'm not sure whether autoindentation could be applied here (:h i_CTRL-F)The result shall be put in a django ftplugin, and it'll even better to put the function into an autoload plugin, with its name changed to django#_expand_block() for instance.Here is the result: EDIT: VA. Support if, for, block. And just copy the statement.function! s:expand_block() abort   Ignore what is after the cursor  let ctx = getline('.')[:col('.')-1]   get sure there is a '%' before the cursor  let statement = matchstr(ctx, '^{%\s*\zs\(block\|if\|for\)\ze.*%')  if !empty(statement)     Avoid triggering InsertLeave events    return }\n\n{% end.statement. %}\<up>\<c-f>     Shorter    return }\n{% end.statement. %}\<esc>O  else    return }  endifendfunctioninoremap <expr> <silent> <buffer> } <sid>expand_block()