Add mapping to rename include guards in c/cpp

This commit is contained in:
Kenneth Benzie 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') let l:lo = synIDattr(synIDtrans(synID(line('.'),col('.'),1)),'name')
echo 'hi<'.l:hi.'> trans<'.l:trans.'> lo<'.l:lo.'>' echo 'hi<'.l:hi.'> trans<'.l:trans.'> lo<'.l:lo.'>'
endfunction 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

View File

@ -91,3 +91,6 @@ nnoremap <leader><CR> :ToggleCheckbox<CR>
" Show highlight groups under the cursor " Show highlight groups under the cursor
nnoremap <leader>hi :CursorHighlightGroups<CR> nnoremap <leader>hi :CursorHighlightGroups<CR>
" Rename C/C++ include guard
nnoremap <leader>rg :call do#rename_include_guard(expand('<cword>'))<cr>