Vim Tips Wiki

Changes: Autocmd for skeleton html file


Back to page

(Redirect, no useful input)
(remove old content)
Line 1: Line 1:
#REDIRECT [[Use eval to create dynamic templates]]
#REDIRECT [[Use eval to create dynamic templates]]
|created=November 25, 2002
|author=Dan Allen
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"
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.

Latest revision as of 12:52, August 14, 2012

  1. REDIRECT Use eval to create dynamic templates

Around Wikia's network

Random Wiki