Currently I have the following mapping in my vimrcnnoremap d _dnnoremap D _Dnnoremap C _Cnnoremap c _cnnoremap <leader>d *dnnoremap <leader>D *DThe result of the above mapping is that everything that is yanked after deleting or changing goes to the black hole register. Now the last problem I am having is after I paste onto a visual line, the replaced text gets yanked on to the clipboard (default) register. So I tried to use this function which attempts to solve this problemfunction! RestoreRegister()  let @ = s:restore_reg  return ''endfunctionfunction! s:Repl()  let s:restore_reg = @  return p@=RestoreRegister()\<cr>endfunctionvmap <silent> <expr> p <sid>Repl()This does not seem to work and I am not sure why. Any help on this issue would be appreciated. Could this have to do with my custom mappings that I defined above?
How would I modify this function to restore from a specified register?
vimscript;cut copy paste;visual mode;register
I'm not sure what's wrong with your function (I didn't look super hard) but there is much simpler solution. Rather than pasting and then restoring the previous register, delete the visual selection to the black hole register before pasting. For example:vnoremap p _dpvnoremap P _dPYou could also provide similar mappings for when you want to capture this to the system clipboard:vnoremap <leader>p *dpvnoremap <leader>P *dP