Hi Jorge,
> Luc, I did install your library but the mapping provided ,,sc didn't
> do anything for me.
You have to select the C cast expression before hitting ,,sc. Depending on your leaderleader, it could be something else.
> 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
Unfortunately, I have to idea which key <80><fc> refers to. It's line 39 from which file? Once you identify it you should be able to provide another keybinding in your .vimrc (or may be in a ftplugin with higher priority)
> 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:
It could be simpler:
" From ftplugin/cpp/cpp_snippets.vim
vnoremap <silent> <buffer> <LocalLeader><LocalLeader>sc
\ <c-\><c-n>:'<,'>call <sid>ConvertToCPPCast('static_cast')<cr>
nmap <silent> <buffer> <LocalLeader><LocalLeader>sc viw<LocalLeader><LocalLeader>sc
function! s:ConvertToCPPCast(cast_type) abort
" Extract text to convert
let save_a = @a
silent normal! gv"ay
" Strip the possible brackets around the expression
" matchlist seems to cause an odd error on multiline C cast expressions: it
" have the fucntion called again.
let [all, type, expr ; tail] = matchlist(@a, '\v^\(\_s*(.{-})\_s*\)\_s*(.{-})\_s*$')
let expr = substitute(expr, '\v^\(\s*(.{-})\s*\)$', '\1', '')
"
" Build the C++-casting from the C casting
let new_cast = a:cast_type.'<'.type.'>('.expr.')'
" Do the replacement
silent exe "normal! gvs".new_cast."\<esc>"
let @a = save_a
endfunction
--
Luc Hermitte
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment