]> git.sthu.org Git - shutils.git/commitdiff
vim: add include guards to C/C++ header files
authorStefan Huber <shuber@sthu.org>
Tue, 5 Nov 2013 16:07:24 +0000 (17:07 +0100)
committerStefan Huber <shuber@sthu.org>
Tue, 5 Nov 2013 16:07:24 +0000 (17:07 +0100)
dotfiles/vim/.vimrc

index a68602e9d83d09117f284bd94698d742a1ef8110..5da54996af79d7730b9e6dfb1fec05781fb8b839 100644 (file)
@@ -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()
 
 
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""