Liaoyuan Li
Liaoyuan Li

Reputation: 11

nvim yank reg keymapping customized

I am trying to simplify an operations yank to "+ reg.

default:In visual mode "+y

I'd go: <leader>y

I have set in my keymap.lua

keymap.set("i","<leader>y","\"+y")

but it doesn't work.

I have read the manual for keymap, but it is too heavy.

Upvotes: 0

Views: 58

Answers (1)

Hercule Poirot
Hercule Poirot

Reputation: 138

If you place "i" as the first argument in the keymap, it means you want to set a keybinding for insert mode, "v" for visual mode, and "n" for normal mode. You can also make keymap availabe in multiple modes, for example:

  • vim.keymap.set({"n", "i", "v" }...
  • vim.keymap.set({"n", "i" }...
  • vim.keymap.set("n", ...

So if you want to remap yanking try to do it in visual mode

Paste command example:

vim.keymap.set("n", '<C-v>', '"+p', { noremap = true, silent = true })

Copy command example:

vim.keymap.set("v", "<C-c>", '"+y', { noremap = true, silent = true })

Upvotes: 1

Related Questions