Skip to content

Instantly share code, notes, and snippets.

@yt-siden
Last active February 7, 2020 02:54
Show Gist options
  • Save yt-siden/81b31e9e02bf82d6548e to your computer and use it in GitHub Desktop.
Save yt-siden/81b31e9e02bf82d6548e to your computer and use it in GitHub Desktop.
Insert UUID-based include guard macro on VIM
" C/C++ insert UUID based include guard
function! s:insert_include_guard()
let s:uuid=system('uuidgen')
let s:uuid=strpart(s:uuid, 0, strlen(s:uuid)-1)
let s:uuid=substitute(s:uuid, '[a-f]', '\u\0', 'g')
let s:uuid=substitute(s:uuid, '\-', '_', 'g')
let s:uuid='UUID_'.s:uuid
call append(0, '#ifndef '.s:uuid)
call append(1, '#define '.s:uuid)
call append('$', '#endif //'.s:uuid)
endfunction
command! -nargs=0 InsertIncludeGuard call s:insert_include_guard()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment