How do I replace a visual selection with some register content without overwriting the unnamed ("") register by the visual selection?
is basically the same, however the answer
xnoremap p "_dP provided there doesn't work properly if applied to a selection that includes the last character of the line (not even the end of line character
$). Furthermore, with this solution, the paste register is hardcoded (to the unnamed one).
I found a partial solution using
"_c<C-R>"<Esc>. This still has the problem that the paste register is hard coded. Furthermore, I don't know how to use this in a vimscript function.
(My main goal is to write a command that takes a motion and then replaces everything between the current cursor position to the motion target by a given register. I currently have this:
noremap s :set opfunc=SensibleSubstitute<CR>g@ function! SensibleSubstitute(type) normal `[v`] normal "_c<C-R>" endfunction
<C-R>" is not recognized and just inserted verbally. Furthermore I don't know how to use the selected register if the user for example types
(PS: the accepted answer here has the same problems with selections at the end of hte line)