5

I'm currently switching to NeoVim using Mac, and unfortunately the yank key doesn't always work as I expect.

I currently use :%w !pbcopy to copy entire documents.

Is there any problem if I remap the yank key to something like !pbcopy? Do you have any tips for that?

Big McLargeHuge
  • 738
  • 2
  • 11
  • 26
Davi Areias
  • 51
  • 1
  • 1
  • 3
  • I don't know about NeoVim, but Vim has the `clipboard=autoselect` option that automatically copies to the clipboard whenever you highlight anything with visual mode. – Heptite Jun 14 '22 at 19:07
  • wow, it has been a long time since I've started learning Vim, I currently just type gg + 0 + v + shift G + y to copy everything, it's obviously not the best way, but I grew used to it – Davi Areias Dec 02 '22 at 15:48
  • 1
    You might get better answers asking this question in [Vi StackExchange](https://vi.stackexchange.com/), which accepts questions for Vim and Neovim too. – Flimm Dec 24 '22 at 14:54

2 Answers2

4

This tells vim/nvim to use the system clipboard for all yank, delete, change and put operations:

set clipboard=unnamedplus

I forget if this works on Mac. You might need to use unnamed instead of unnamedplus, or do something like this:

if has("unnamedplus")
    set clipboard=unnamedplus
else
    set clipboard=unnamed
endif
Big McLargeHuge
  • 738
  • 2
  • 11
  • 26
0

As mentioned in the comments to the other answer, non-macOS users will also need to ensure that the right clipboard tools are installed. You can view requirements via :h provider-clipboard. For example, for Linux + Wayland setup, you can install wl-clipboard. After logging out and back in, I was able to get a shared clipboard running with :set clipboard=unnamedplus in neovim.

Isa
  • 1
  • 2