first line
second line
If you now go to the second line and yank it, then go to the first line and type in
"_ddp
What I'd expect to happen is:
second line
second line
What actually happens is:
second line
The `p` doesn't do anything at all, unless you press it a second time.
After some experimentation, I figured out that the `v:register` variable is not reset after the `"_dd` operation. As a result, the following `p` uses the `_` register. This is reproducible with other registers as well. If you do anything after the `"_dd` (like move down one line with `j`), the register is reset just fine and `p` uses the default one.
The original issue that brought this to my attention is here if you'd like more context: https://github.com/AndrewRadev/whitespaste.vim/issues/2
Given a text file with the following two lines:
first line
second line
If you now go to the second line and yank it, then go to the first line and type in
"_ddp
What I'd expect to happen is:
second line
second line
What actually happens is:
second line
The `p` doesn't do anything at all, unless you press it a second time.
> Can you please come up with a mapping that shows the wrong behaviour?
I made this example: https://gist.github.com/AndrewRadev/11408444
It's supposed to paste some text and comment it in the process. It's kind of silly, but a realistic enough example. If you `"_dd` anything and then immediately perform a `gp`, nothing happens, since the `v:register` variable is set to `_`. If you've managed ot fix the issue, it should paste normally, from the default register.
Best Regards,
Andrew.
> Thanks. I think this one fixes it.
Yes, it seems like it does. I just applied it to my local vim and everything seems to work fine.
> (I hope, it doesn't have any side effect).
So do I :).
Thanks for the fix! I guess all that's left is to wait until it's merged.
Best Regards,
Andrew.
exe "nmap <buffer> " . g:pasta_paste_before_mapping . " <Plug>BeforePasta"
nnoremap <silent> <Plug>BeforePasta :<C-U>call <SID>NormalPasta('P', 'O')<CR>
function! s:NormalPasta(p, o)
" ...
exe "normal! " . a:o . "\<space>\<bs>\<esc>" . v:count1 . '"' . v:register . ']p'
" ...
endfunction
With Christian's patch, it seems like this doesn't work. The plugin uses the default register regardless of how I invoke the paste mapping. If I understand what Ingo's saying, any normal-mode command, including :, should clear v:register. If this is what Christian's patch is doing, it would explain why v:register is lost in the above case. And I think it's a pretty common use case to build up a <Plug> mapping by calling a command or function. In fact, if : resets v:register, I'm not sure how it would even be possible to access that variable in order to save it.
The way I *think* it should work is: Particular operators like d, y, p "consume" a register. Once they're done, the v:register can safely be reset to the default. As Ingo says, typing "xyy should reset v:register, but typing "x: should not, since the register was just left hanging for the next operations.
At least that's how I see the "correct" functionality, but I'm starting to feel pretty confused about edge cases. Can anybody say whether my line of thinking is in the right direction?