The very first thing you should do is try vimtutor
and complete it a couple of times. Once the basics are covered you can start to play with plugins…
SnipMate is inspired by TextMate's snippets and/so is beautiful, it has a lot of HTML snippets by default and it's extremely easy to add your own. To use it, type div
then hit Tab to obtain:
<div id="|">
</div>
with the caret between the ""
ready for you to type an id; hit Tab again to move the caret on the blank line:
<div id="myId">
|
</div>
Beautiful. Many editors have this feature, though.
If you have a lot of HTML to write — say a few emails/newsletters a day — another plugin called SparkUp allows you to produce complex HTML with only a few key strokes and some CSS knowledge. You start by typing something like:
table[id=myTable] > tr*3 > td*2 > img
then you hit <C-e>
(CtrlE) to obtain:
<table cellspacing="0" id="myTable">
<tr>
<td>
<img src="|" alt="" />
</td>
<td>
<img src="" alt="" />
</td>
</tr>
<tr>
<td>
<img src="" alt="" />
</td>
<td>
<img src="" alt="" />
</td>
</tr>
<tr>
<td>
<img src="" alt="" />
</td>
<td>
<img src="" alt="" />
</td>
</tr>
</table>
with the caret inside the first empty ""
. Hit <C-n>
and <C-p>
to go to the next/previous field.
Magical. The plugin is available for more editors, though.
I second text objects and Surround.vim which are unbelievably useful.
Another cool feature is the visual-block mode (:help visual-block
) where you can select columns of text. Say you have:
<ul>
<li><p>My text doesn't mean anything</p></li>
<li><p>My text doesn't mean anything</p></li>
<li><p>My text doesn't mean anything</p></li>
<li><p>My text doesn't mean anything</p></li>
</ul>
place your cursor on the >
of the first <li>
then hit <C-v>
and move the cursor downward to the fourth <li>
. Hit I
(capital I) to enter INSERT mode just before the >
and type class="myElement"
then <Esc>
to obtain:
<ul>
<li class="myElement"><p>My text doesn't mean anything</p></li>
<li class="myElement"><p>My text doesn't mean anything</p></li>
<li class="myElement"><p>My text doesn't mean anything</p></li>
<li class="myElement"><p>My text doesn't mean anything</p></li>
</ul>
Ho yeah!
Seriously, Vim is great.