Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to be able to select several lines using vim when editing an HTML file, then enter some hotkey and get these lines wrapped in a django comment block.

For example, I have:

one line
another line

I want to get:

{% comment %}
one line
another line
{% endcomment %}
share|improve this question

2 Answers 2

Maybe worth to take a look to this vim plugin http://www.vim.org/scripts/script.php?script_id=1697

share|improve this answer

I have the following mapping set up to quickly disable a block of C++ code using #if 0...#endif

:vmap 0 V'<O#if 0<Esc>'>o#endif<Esc>

What this does is set up a mapping that only works while Visual mode is enabled (vmap), which disables visual mode (V), goes to the beginning of the last visual selection ('<), enters a new line above it (O), enters the "#if 0" text then quits edit mode (<Esc>), then goes to the end of the last visual selection ('>), adds a line below (o) and enters the "#endif" text.

You could do something similar by replacing the start and end text, e.g.

:vmap 0 V'<O{% comment %}<Esc>'>o{% endcomment }<Esc>

Note that this requires the use of line-by-line visual mode, entered with a capital V, rather than character-by-character visual mode that uses a lowercase v.

share|improve this answer
It works! Thank you for simple clean solution. –  lorien Aug 4 '11 at 6:19
I've tried to use your solution for character visual mode and failed. If I use v and select some chars and press EscEsc and press '< or '> (in both cases) I get on first non-space character of line where I've selected some characters. –  lorien Aug 4 '11 at 7:42
Yeah, I guess this does not work for character visual mode, it is after all a line-based operation. –  OrbWeaver Aug 4 '11 at 8:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.