Can someone recommend a function that would allow to do this in vim?
Or outside vim, can anyone recommend a tool that would be useful in doing this?
Thank you!
thanks you for the advice. I agree that it is not a good idea to blindly replace everything. The most common case for me is probably static_cast so I would do that by default.
> In lh-cpp (*), I have 3 mappings that transform C casts into C++ casts -- and 6 more to cast an expression.
>
> This has to be done manually: you'll have to know if you want a const_cast, a static_cast, or a reinterpret_cast. As Dominique said, it can't really be done automatically. May be, clang could automate many things, but it won't be able to know whether you want to downcast with a dynamic_cast or with a static_cast?
>
> (*) https://github.com/LucHermitte/lh-cpp
>
Luc, I did install your library but the mapping provided ,,sc didn't do anything for me.
I did have an error when entering a c++ buffer after loading the plugin with VAM, something like:
line 39:
E227: mapping already exists for <80><fc>^D
I am not sure this is the reason I cannot use the mapping provided in your plugin.
I did write a function and mapping that for now should suit my needs:
function! ToStatic1()
" (type) b -> static_cast<type>(b)
" it is assumed cursor is inside the first cast
let original_keyword = &iskeyword
setlocal iskeyword +=_
setlocal iskeyword +=[
setlocal iskeyword +=]
setlocal iskeyword +=:
normal di(
let @a = @"
normal da(
normal istatic_cast<>
normal h
normal "ap
normal f>l
while 1
"get current char
let c = getline('.')[col('.')-1]
if c == ' '
normal x
else
break
endif
endwhile
echom c
if c != '('
normal i(
normal e
normal a)
endif
let &iskeyword=original_keyword
endfunction
nnoremap <silent> ,a :call ToStatic1()<CR>
Thanks,
Jorge