Skip to content

Instantly share code, notes, and snippets.

@youngsofun
Forked from yt-siden/insert_guard.vim
Created May 12, 2018 00:40
Show Gist options
  • Save youngsofun/48cacc0bbe3dd06859665ecb469c61a8 to your computer and use it in GitHub Desktop.
Save youngsofun/48cacc0bbe3dd06859665ecb469c61a8 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