Add mapping to rename include guards in c/cpp

This commit is contained in:
2018-09-07 22:13:29 +01:00
parent 25c18763bc
commit c80ddd3617
2 changed files with 17 additions and 0 deletions

View File

@@ -54,3 +54,17 @@ function! do#cursor_highlight_groups()
let l:lo = synIDattr(synIDtrans(synID(line('.'),col('.'),1)),'name')
echo 'hi<'.l:hi.'> trans<'.l:trans.'> lo<'.l:lo.'>'
endfunction
" Rename C/C++ include guard
function! do#rename_include_guard(old)
" Prompt for new guard name
let l:new = input('Rename include guard: ', a:old)
" Set a mark to jump back to
normal mr
" Replace the old guard name with the new one
exec '%s/\(#ifndef\|#define\|#endif\s\+\/\/\)\s\+\zs'.a:old.'/'.l:new.'/g'
" Stop highlighting search results
nohlsearch
" Jump back to the set mark
normal 'r
endfunction