Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pasteboard(or register) will be rewrite if paste something on visual mode #1743

Closed
omega-ult opened this issue May 24, 2017 · 21 comments
Closed

Comments

@omega-ult
Copy link

  • Click thumbs-up 👍 on this issue if you want it!
  • Click confused 😕 on this issue if not having it makes VSCodeVim unusable.

The VSCodeVim team prioritizes issues based on reaction count.


BUG REPORT

Environment:

  • VSCode Version:1.12
  • VsCodeVim Version: 0.7.1
  • OS: Win7

What happened:If you copy something to pasteboard like "aY, then select some new stuff in visual mode, then "ap, that's exact what you want, but if you do it again, "ap, the word selected in last visual mode will be pasted.

What did you expect to happen: In last version, things go well, what I keep in register[a] will be pasted, instead of replaced one.

How to reproduce it:Always happen.

@Chillee
Copy link
Member

Chillee commented May 24, 2017

It's a result of this: #1280

It seems that we shouldn't be yanking to the specified register.

@omega-ult
Copy link
Author

Well, I gotta change my method.

@Chillee
Copy link
Member

Chillee commented May 24, 2017

No, it's a valid bug. I was just noting the cause.

@Chillee Chillee reopened this May 24, 2017
Chillee added a commit that referenced this issue May 29, 2017
Fixes #1743: Fixed pasting over visual mode with named register overwriting the named register
@DrakeXiang
Copy link

this behavior appeared since a few versions back, I thought it would be fixed soon since it's so buggy, now I'm still experiencing it, nobody use this function like this ???

@Chillee
Copy link
Member

Chillee commented Sep 20, 2017

@DrakeXiang The behavior seems to be correct for me,

@DrakeXiang
Copy link

@Chillee Ok, turns out this is the correct behavior in vim, didn't know that... so this is painful if you have to paste multiple times

@Chillee
Copy link
Member

Chillee commented Sep 26, 2017

@DrakeXiang Yeah :(

The right thing to do is to copy into a register with "ay. You can then paste without overwriting that register by selecting the text you're trying to replace and doing "ap. You can then simply use dot repeat to repeat that multiple times.

@chibicode
Copy link
Contributor

@Chillee this will be solvable by mapping p to "_dP only in visual mode. However that's not currently possible, so I made a new issue:

#2705

@chibicode
Copy link
Contributor

This can now be fixed with:

    "vim.visualModeKeyBindingsNonRecursive": [
        {
            "before": [
                "p",
            ],
            "after": [
                "p",
                "g",
                "v",
                "y"
            ]
        }
    ],

#2726
#2744

@peterlindsten
Copy link

@chibicode Thanks for the workaround. This should be standard though?

@jeromecovington
Copy link

This is the expected behavior in vim. I have to override in in vimrc usually. I'm glad I know how to override it in vscode now as well, thanks!

@xh3b4sd
Copy link

xh3b4sd commented May 26, 2020

Using the configuration from @chibicode does not work for me. Pasting overwrites the register still and consecutive pastes do not apply the initially yanked content. Any advice on this?

@xh3b4sd
Copy link

xh3b4sd commented May 26, 2020

Maybe more info from my side. I figured I can select and paste the right content multiple times with ve and then p again, over and over again. My muscle memory wants to do that by simply repeating the last paste command I did using .. And this does not work. Any way to get this sorted?

@J-Fields
Copy link
Member

@xh3b4sd This is expected behavior. From :help:

The previously selected text is put in the unnamed register. If you want to
put the same text into a Visual selection several times you need to use
another register. E.g., yank the text to copy, Visually select the text to
replace and use "0p . You can repeat this as many times as you like, the
unnamed register will be changed each time.

@xh3b4sd
Copy link

xh3b4sd commented May 27, 2020

I understand that. My question is how I can just repeat the last paste. I am used to only type . again and the whole functionality is replicated. This is super easy and useful but I can't figure how to do that in vsCode. The complexity of ve"0p all over again kills my workflow and is so much more typing.

@stargoo
Copy link

stargoo commented Jun 15, 2020

@chibicode 's workaround is okay, but I found that it doesn't work with multiline operations too well, as the document will scroll to the last yank. This is jarring to say the least. "0p can be a pain, but you can still use p if you like. The rebind fixes the multiline jumping, but note that it will not work with the repeat, . key.

"vim.visualModeKeyBindingsNonRecursive": [  
{  
            "before": [  
                "p",  
            ],  
            "after": [  
                "p",  
                "`",  
                "[",  
                "v",  
                "`",  
                "]",  
                "h",  
                "y",  
                "<Esc>"  
            ]  
        }  
    ],  

@proxseas
Copy link

proxseas commented Jun 8, 2022

Any updates to this? It would be fantastic if there was a config setting that would prevent the yank register from being overwritten when you paste over something in visual mode.

EDIT: I found this to be a great solution:

  "vim.visualModeKeyBindingsNonRecursive": [
    {
      "before": ["p"],
      "commands": [
        "editor.action.clipboardPasteAction"
      ]
    }
  ],

Source: link and link

@msomeone
Copy link

msomeone commented Dec 5, 2022

"vim.normalModeKeyBindingsNonRecursive": [
{ "before": ["p"], "commands": [ "editor.action.clipboardPasteAction", "extension.vim_escape"] },
],

"vim.visualModeKeyBindingsNonRecursive": [
{ "before": ["p"], "commands": [ "editor.action.clipboardPasteAction", "extension.vim_escape"] },
{ "before": ["y"], "commands": [ "editor.action.clipboardCopyAction", "extension.vim_escape"] }
],

worked for me better

@J-Fields
Copy link
Member

J-Fields commented Dec 5, 2022

P in Visual mode pastes without overwriting the register

@hliebert
Copy link

This works.

    "vim.visualModeKeyBindingsNonRecursive": [
        {
            "before": [
                "p"
            ],
            "after": [
                "P"
            ],
        }
]

@ShimmyTheDev
Copy link

If anyone needs it, this is my solution:

    "vim.visualModeKeyBindingsNonRecursive": [
        {
            "before": [
                "p"
            ],
            "commands": [
                "editor.action.clipboardPasteAction",
                "extension.vim_escape"
            ]
        }
    ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests