Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Björn-Egil Dahlberg committed Sep 22, 2012
0 parents commit 41aec78
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
Empty file added LICENSE
Empty file.
27 changes: 27 additions & 0 deletions README.md
@@ -0,0 +1,27 @@
Header Comments in Vim
----------------------

A simple vim-plugin to generate header comments
for Author, Copyright and Creation Date.

Example:

%%
%% Copyright (C) 2012 Hapida AB
%%
%% File: test.erl
%% Author: Björn-Egil Dahlberg
%% Created: 2012-09-22
%%


Author and Copyright holder is set in your .vimrc

Example:

" Define headers for copyright and author
let g:header_comment_author = "Björn-Egil Dahlberg"
let g:header_comment_copyright = "Hapida AB"

Note:
This plugin was mainly created to get an idea on how vim plugins works =)
Empty file added doc/header-comment.txt
Empty file.
42 changes: 42 additions & 0 deletions plugin/header-comment.vim
@@ -0,0 +1,42 @@
"
" Copyright (C) 2012 Hapida AB
"
" File: header-comment.vim
" Author: Björn-Egil Dahlberg
" Created: 2012-09-22
"

autocmd bufnewfile *.erl call MakeFileHeader('%%','%%','%%')
autocmd bufnewfile *.hrl call MakeFileHeader('%%','%%','%%')
autocmd bufnewfile *.vim call MakeFileHeader('" ','" ','" ')
autocmd bufnewfile *.c call MakeFileHeader('/* ',' *',' */')

" Header
" fc = firstcomment, ex. /*
" mc = middle comments ex. *
" lc = last comment ex. */
function! MakeFileHeader(fc,mc,lc)
set paste
let s:author = ""
let s:copyright = ""
if exists('g:header_comment_author')
let s:author = g:header_comment_author
else
echo "g:header_comment_author is not defined in .vimrc"
end
if exists('g:header_comment_copyright')
let s:copyright = g:header_comment_copyright
else
echo "g:header_comment_copyright is not defined in .vimrc"
end

let s:comment = a:fc . "\r"
let s:comment .= a:mc . " Copyright (C) " . strftime("%Y") . " " . s:copyright . "\r"
let s:comment .= a:mc . "\r"
let s:comment .= a:mc . " File: " . expand('%:t') . "\r"
let s:comment .= a:mc . " Author: " . s:author . "\r"
let s:comment .= a:mc . " Created: " . strftime("%Y-%m-%d") . "\r"
let s:comment .= a:lc . "\r"
exec "normal i" . s:comment
set nopaste
endfunction

0 comments on commit 41aec78

Please sign in to comment.