VIM: Using surround.vim with customizations for Django Templates

So, just sat down to look again at using Django templates with the google app-engine and now using my *new* text-editor of choice vim, I thought I would invest some time in improving the experience.  I got told of a plug-in a couple of months ago which made creating html mark-up, simply like magic, and the plugin I mean is called surround.vim : http://www.vim.org/scripts/script.php?script_id=1697

Out of the box this simply works amazingly well with the tag encapsulation you need with HTML, just have a peek at the documentation on that link :) .  With Django templates, there is some more syntax which needs to be introduced, and the first two customizations I have added are shortcuts to specify content placeholders and also the master page declaration.

Content Placeholders

The following line is the desired out come:

{% block title %}{% endblock %}

To achieve this I simply type :

title

followed by the key combinations:

yss-

This simply wraps the title word with the required syntax.  You will notice I have used the ASCII code from the docs but just changed its function.

Master Page Declaration

The following line is the desired out come:

{% extends “shared/main_master.html” %}

To achieve this I simply type:

“shared/main_master.html”

followed by the key combinations:

yss/

The mappings inside of the surround.vim

The following are the two lines which I am currently using the achieve the above *shortcuts.*

<
	let g:surround_45 = "{% block  \r %}{% endblock %}"
	let g:surround_47 = "{% extends \"\r\" %}"
>

WIN!


No Comments

Start the ball rolling by posting a comment on this article!

Leave a Reply




XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>