From: Stefan Huber Date: Tue, 5 Nov 2013 16:07:24 +0000 (+0100) Subject: vim: add include guards to C/C++ header files X-Git-Url: https://git.sthu.org/?p=shutils.git;a=commitdiff_plain;h=ba8d944658a4e8b99d9c5e4762da74ca5475d213 vim: add include guards to C/C++ header files --- diff --git a/dotfiles/vim/.vimrc b/dotfiles/vim/.vimrc index a68602e..5da5499 100644 --- a/dotfiles/vim/.vimrc +++ b/dotfiles/vim/.vimrc @@ -168,6 +168,19 @@ function EscapeHexToChar() execute '%s/^\(.*\)$/"\1"/' endfunction +function InsertIncludeGuardsWithoutEndif() + let gatename = substitute(expand("%:t"), "\\.", "_", "g") . '_' . strpart(system('pwgen -c 16 1'), 0, 16) + execute "normal! i#ifndef " . gatename + execute "normal! o#define " . gatename +endfunction + +function AddIncludeGuards() + execute "normal! Go#endif" + execute "normal! gg" + call InsertIncludeGuardsWithoutEndif() +endfunction + +autocmd BufNewFile *.{h,hpp} call AddIncludeGuards() """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""