‹ back home

Selection / clipboard cheatsheet

2022-12-03 #clipboard

There’s multiple selections:

Vim (& derivates)

Vim has registers. They are accessed by prefixing "X, where X is a register name. These extend the ones above:

Neovim config example:

Copying to the PRIMARY selection:

-- Copy to PRIMARY selection on mouse selection.
vim.keymap.set("v", "<LeftRelease>", '"*ygv')

-- Yank (copy) to PRIMARY selection by default (e.g.: with `yy`).
vim.opt.clipboard = "unnamed"

Copying to CLIPBOARD is also possible, but confusing in terminals:

-- Copy to CLIPBOARD selection with ctrl+c.
vim.keymap.set("v", "<C-c>", '"+ygv')

-- Paste from CLIPBOARD selection with ctrl+v.
vim.keymap.set("v", "<C-v>", '"+p')

Note that the usual mappings for Ctrl+Shift+c (or Cmd+c) should work fine on terminals.

— § —