diff --git a/autoload/do.vim b/autoload/do.vim index 25900e2..380c5d2 100644 --- a/autoload/do.vim +++ b/autoload/do.vim @@ -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 diff --git a/plugin/mappings.vim b/plugin/mappings.vim index 1a7e1ae..e1c75bd 100644 --- a/plugin/mappings.vim +++ b/plugin/mappings.vim @@ -91,3 +91,6 @@ nnoremap :ToggleCheckbox " Show highlight groups under the cursor nnoremap hi :CursorHighlightGroups + +" Rename C/C++ include guard +nnoremap rg :call do#rename_include_guard(expand(''))