It's been a while since I've had to do any HTML-like code in Vim
, but recently I came across this again. Say I'm writing some simple HTML
:
<html><head><title>This is a title</title></head></html>
How do I write those closing tags for title, head and html down quickly? I feel like I'm missing some really simple way here that does not involve me going through writing them all down one by one.
Of course I can use CtrlP to autocomplete the individual tag names but what gets me on my laptop keyboard is actually getting the brackets and slash right.
I find using the xmledit plugin pretty useful. it adds two pieces of functionality:
<p>
), it expands the tag as soon as you type the closing >
into <p></p>
and places the cursor inside the tag in insert mode.If you then immediately type another >
(e.g. you type <p>>
), it expands that into
<p>
</p>
and places the cursor inside the tag, indented once, in insert mode.
The xml vim plugin adds code folding and nested tag matching to these features.
Of course, you don't have to worry about closing tags at all if you write your HTML content in Markdown and use %!
to filter your Vim buffer through the Markdown processor of your choice :)