I have several mappings for this task in lh-cpp .
In this case, it will be ,,sc , or ,,rc , or ,,dc . (here , actually my <localleader> ).
It is actually implemented as:
function! s:ConvertToCPPCast(cast_type) " Extract text to convert let save_a = @a normal! gv"ay " Strip the possible brackets around the expression let expr = matchstr(@a, '^(.\{-})\zs.*$') let expr = substitute(expr, '^(\(.*\))$', '\1', '') " " Build the C++-casting from the C casting let new_cast = substitute(@a, '(\(.\{-}\)).*', \ a:cast_type.'<\1>('.escape(expr, '\&').')', '') " Do the replacement exe "normal! gvs".new_cast."\<esc>" let @a = save_a endfunction vnoremap <buffer> <LocalLeader><LocalLeader>dc \ <c-\><cn>:'<,'>call <sid>ConvertToCPPCast('dynamic_cast')<cr> nmap <buffer> <LocalLeader><LocalLeader>dc viw<LocalLeader><LocalLeader>dc ...
Luc hermitte
source share