URL:         https://www.vim8.org/html.html
Created:     Sat Feb 17 00:00:00 MET 1996
Last update: Thu Feb 26 21:00:00 CET 1998

VIM - HTML Editing

Some tips for mappings and abbreviations for HTML editing.

The current file with my HTML setup for Vim is available as:

http://www.math.fu-berlin.de/~guckes/vim/source/html.vim

The file contains

I will try to explain some of the ideas on this page, but do not expect all things to be explained here. Instead, look at the file itself!

OK, here we go:


Time and date stamps

Have you ever wondered how recent the information on a page is? And when you search for info then you don't find any hint about the last update. grrr

But it is so easy to give a page a date/time stamp! Every page should have an update time stamp so that you know how recent the info is.

So far I had been using a mapping to call an external "date" command to give the date and time - but now that Vim-5 has a builtin function for this there is no need for an external command at all. It can be done with a simple abbreviation that uses the function "strftime":

iab YDATE <c-r>=strftime("%a %b %d %T %Z %Y")<cr> " Example: Tue Dec 16 12:07:00 CET 1997 Just enter the word "YDATE" and you'll get the current date and time.

This can be used to put this data right after some text like "Last update:":

" ,L = "Last updated" - replace old time stamp with a new one " preserving whitespace and using internal "strftime" command: " requires the abbreviation "YDATE" map ,L 1G/Last update:\s*/e+1<cr>CYDATE<esc> " Example: " before: "Last update: Thu Apr 6 12:07:00 CET 1967" " after: "Last update: Tue Dec 16 12:07:00 CET 1997" As this commands jumps to the line with "Last update:" you will leave the current line. To jump back where you have been before use the command ^O.

There are some more abbreviations in my html.vim for adding the date or time - check them out!


ABbreviations and MAPpings

Some HTML are just inserted as abbreviated text. But when you add HTML to an existing text eg for putting a link on some text, then you should use Vim's "visual selection" and the visual commands from my setup file.

I have chosen the letter 'Y' as the first letter within abbreviated words as this letter isn't used very much. Almost every "vmap" (a mapping which applies only to visual mode) I have created have the same name as the abbreviations, only they start with a comma (',') as the first "letter", as the 'Y' might be used as a command by itself.

[TODO: Add example.]

If you have any question about one of my mappings then please ask me!


Credits

Thanks to Dan Astoorian [email protected] who told me about the XMP tag for HTML!

Douglas J. Renze ([email protected]) for some more tips on HTML:

http://www.avalon.net/~drenze/vi/macros/HTML.html


Back to the -> VIM Home Page

Send feedback on this page to

Sven Guckes [email protected]