0

I want to make Neovim stop yanking the text I paste over into my register (mapped to system clipboard with vim.opt.clipboard = 'unnamedplus'), eg

If I have the text:

asdfghjkl
asdfghjkl
asdfghjkl

and I v over 'sdfgh', hit y, then go to the second line and v over 'as' and hit paste it will copy 'as' to my clipboard, I want it to keep 'sdfgh' instead

1

2 Answers 2

4

Just use P instead of p in visual mode. This will preserve the register.

To make this default, you can use a map such as

xnoremap p P
3
  • Will this not also make regular p behave like P (eg alter paste position etc ?)
    – Madoka
    Nov 7, 2022 at 3:50
  • @Madoka xnoremap only affects Visual modes.
    – D. Ben Knoble
    Nov 8, 2022 at 18:51
  • @d-ben-knoble Ah, okay Thank You !
    – Madoka
    Nov 8, 2022 at 23:42
0

If you are using lua, update your keymaps.lua file to include:

-- mode
--  "n" - normal mode
--  "i" - insert mode
--  "v" - visual mode

local function map(m, k, v)
    vim.keymap.set(m, k, v, { silent = true })
end

map("v", "p", "P", { noremap = true, silent = true })

This remaps p, which yanks text on paste with P, which doesn't yank text on paste.

1
  • oh, good idea! i ended up setting a remap for pgvy as p instead so it yanks back whatever the selected text before pasting was but this is a good idea too!
    – Madoka
    Mar 3 at 2:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.