sponsor Vim development Vim logo Vim Book Ad

basic Tip #375: autocmd for skeleton html file (BufFileNew)

 tip karma   Rating 19/7, Viewed by 955 

created:   November 25, 2002 12:23      complexity:   basic
author:   Dan Allen      as of Vim:   5.7

How about starting your new html document with a nice shiny skeleton!

Add this in your autocmd section in your .vimrc file

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

 rate this tip  Life Changing Helpful Unfulfilling 

<<VIM's Filtering Commands Summary | A totally useless tip...or is it ? >>

Additional Notes

bigredlinux at yahoo.com, November 25, 2002 12:26
The tip added endlines where they are not supposed to be...please remove all endlines so that the command list just a single line.
[email protected], November 26, 2002 2:36
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"
perry.tew cibavision.novartis.com, October 21, 2003 11:59
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"
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo