Does a plugin exist which provides these text objects for Django templates? For example, in HTML/XML if I have the following text
<p>This is some text.<p>
and my cursor is positioned anywhere inside the tags, I can use cit
to change the text inside the tags. I'm looking for something similar for Django templates. For example, with the text
{% block title %}This is the title{% endblock %}
I'd like the same behavior. If nothing exists, any vimscripters out there know if this is possible and willing to give some hints?
Thanks!
Have a look on the official Django documentation. There is a "Using Vim with Django" section.
https://code.djangoproject.com/wiki/UsingVimWithDjango
and a surround mapping part.
Here is an extract :
let b:surround_{char2nr("v")} = "{{ \r }}"
let b:surround_{char2nr("{")} = "{{ \r }}"
let b:surround_{char2nr("%")} = "{% \r %}"
let b:surround_{char2nr("b")} = "{% block \1block name: \1 %}\r{% endblock \1\1 %}"
let b:surround_{char2nr("i")} = "{% if \1condition: \1 %}\r{% endif %}"
let b:surround_{char2nr("w")} = "{% with \1with: \1 %}\r{% endwith %}"
let b:surround_{char2nr("f")} = "{% for \1for loop: \1 %}\r{% endfor %}"
let b:surround_{char2nr("c")} = "{% comment %}\r{% endcomment %}"
Put the above in ~/.vim/ftplugin/htmldjango.vim.
Examples in visual mode (select some text first):
PS : another possibility is the use of eclim (vim + eclipse) which supports Django project and template editing http://eclim.org/vim/python/django.html but that's a lot heavier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With