Wednesday, December 29, 2010

Add Custom Header to scripts using vim



1. Create a template header: cat ~/.vim_header.pl

:insert
#
# $Id: $
#
# Copyright (c) 2011 Parag Kalra
# All rights reserved.
#
## @script
##
## @summary
##
## @description
##
## @usage
##
## @synopsis
##
## @param
##
## @keywords
##
## @status review
##
## @author
##
## @creation-date
##
## @last-modified
##
## @burts
##
## see-also
.

:insert should be present on first line and . should be present on last line

2. Add following lines to ~/.vimrc

autocmd bufnewfile *.pl so ~/.vim_header.pl
autocmd bufnewfile *.pl exe "1," . 30 . "g/@script.*/s//@script " .expand("%")
autocmd bufnewfile *.pl exe "1," . 30 . "g/@creation-date/s//@creation-date " .strftime("%d-%m-%Y")
autocmd Bufwritepre,filewritepre *.pl execute "normal ma"
autocmd Bufwritepre,filewritepre *.pl exe "1," . 30 . "g/last-modified/s/last-modified .*/last-modified " .strftime("%c")
autocmd bufwritepost,filewritepost *.pl execute "normal `a"

3. Now create a new file having .pl extension and see the magic.

No comments: