Skip to content

Instantly share code, notes, and snippets.

@posva
Created August 17, 2014 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save posva/1ece81bf7127ab3e257c to your computer and use it in GitHub Desktop.
Save posva/1ece81bf7127ab3e257c to your computer and use it in GitHub Desktop.
Use Ctr+H to add the classic header with defines guards for C/C++ files
" fill rest of line with characters
function! FillLine( str, l )
" strip trailing spaces first
.s/[[:space:]]*$//
" calculate total number of 'str's to insert
let reps = (a:l - col("$")) / len(a:str)
" insert them, if there's room, removing
" trailing spaces (though forcing
" there to be one)
if reps > 0
.s/$/\=(repeat(a:str, reps))/
endif
endfunction
let name = 'Eduardo San Martin Morote'
let email = 'i@posva.net'
let web = 'http://posva.net'
map <buffer> <C-H> <ESC>ggO/**<ESC>:call FillLine("*", 81)<CR>A<CR> <C-R>=expand("%:t:r")<CR><ESC>:call FillLine(" ", 80)<CR>A*<CR><C-R>=strftime("%a %b %d %Z %Y")<CR><ESC>:call FillLine(" ", 80)<CR>A*<CR>Copyright <C-R>=name<CR><ESC>:call FillLine(" ", 80)<CR>A*<CR><C-R>=email<CR><ESC>:call FillLine(" ", 80)<CR>A*<CR><C-R>=web<CR><ESC>:call FillLine(" ", 80)<CR>A*<CR><ESC>:call FillLine("*", 80)<CR>A/<CR><ESC>ggO#ifndef __<C-R>=expand("%:t:r")<CR>_H__<ESC>^f gUg_o#define __<C-R>=expand("%:t:r")<CR>_H__<ESC>^f gUg_Go#endif<ESC>kko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment