History
Article Edit this page Discussion

Autocmd for skeleton html file

From Vim Tips Wiki

Jump to: navigation, search

Tip 375 Previous Next Created: November 25, 2002 Complexity: basic Author: Dan Allen Version: 5.7


How about starting your new html document with a nice shiny skeleton! Add this in your autocmd section in your vimrc:

" Start with an html skeleton document when opening a new *.html file
au BufNewFile *.html | execute "normal! :set ai!\<kEnter>i<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\<kEnter><html>\<kEnter> <head>\<kEnter> <style>\<kEnter> </style>\<kEnter> <script>\<kEnter> </script>\<kEnter> </head>\<kEnter> <body>\<kEnter> </body>\<kEnter></html>\<Esc>:set ai\<kEnter>gg"

[edit] References

[edit] Comments

Slight Variant (without tabs/spaces)

au BufNewFile *.html | execute "normal! :\<kEnter>i\<html>\<kEnter><head>\<kEnter><title>title</title>\<kEnter><script>\<kEnter></script>\<kEnter></head>\<kEnter><body>\<kEnter></body>\<kEnter></html>\<Esc>gg"

I added some spaces to make the indentation a little prettier:

au BufNewFile *.html | execute "normal! :\<kEnter>i\<html>\<kEnter> <head>\<kEnter> <title></title>\<kEnter> <script language=\"javascript\">\<kEnter> </script>\<kEnter> </head>\<kEnter> <body>\<kEnter> </body>\<kEnter></html>\<Esc>gg"

TODO Make a choice/fix the snippets. None of the code snippets really looked good in my environment (because of indenting issues). Morevover all three have a little something the others don't have. (May I say using a template-file loader/expander provides templates easier to tweak?... :-/ -> :help template).

Anyway, I'm quite sure there are many template/snippets tips out there. Let's start by finding them all.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Pixar
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Dark Shadows
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions


Vote for collaboration of the month.

Send this article to a friend
"Autocmd for skeleton html file"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation