I use the following two snippets of HTML frequently:
<开发者_StackOverflow中文版a href="" title=""></a><br />
<br />
and
<a href="" title=""</a><br />
<hr class="grp">
Is there a way where I can quickly insert one or the other into my file?
You can store them in files, then
:r name_of_snippet_file
to 'read' them into the current file, where the cursor is.
You can enhance Vim with many plugins/scripts. A quick google hit brought me snipMate (haven't tried it), which seems to do what you ask for. Of course, you can also insert a snippet by reading a file, but maybe using tab-completion is a little bit more convenient.
If you find yourself typing a lot of html, I can strongly recommend the zencoding plugin. Zencoding expands html/xml tags and offers many more ways to write html (e.g. converting some lines into an unsorted list).
Why not add an abbreviation to your .vimrc
I have the following in my .vimrc for c++ files:
iabbrev cout cout << "" << endl;<left><left><left><left><left><left><left><left><left><left>
It lets my just type "cout" and then prints:
cout << "" << endl;
Placing my cursor inside the quotes...
Type ":help iabbrev" in vim for a reasonable tutorial on how this works...
You can map a button to insert the text into the preceding line:
:map <F1> o<a href="" title=""></a><br /><ENTER><br /><ESC>
^ ^ ^ ^
The interesting bits are marked by ^'s and explained below
o
starts inserting on the line below the cursor,
O
instead would start inserting on the line above the cursor,
<ENTER>
inserts a newline character,
<ESC>
exits insert mode.
If you would prefer you can use :imap
instead of :map
this will make it work in insert mode. In that case you would probably want to escape out of insert mode at the beginning and then not escape out at the end
:imap <F1> <ESC>o<a href="" title=""></a><br /><ENTER><br />
精彩评论