From ba8d944658a4e8b99d9c5e4762da74ca5475d213 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Tue, 5 Nov 2013 17:07:24 +0100 Subject: [PATCH] vim: add include guards to C/C++ header files --- dotfiles/vim/.vimrc | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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() """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -- 2.30.2