vimclipboardwaylandvim-registers

How to copy from Vim to system clipboard using wayland and without compiled vim `+clipboard` feature flag


I cannot copy into the + or * register.

:echo has('clipboard') from within Vim returns 0 meaning I don't have that feature flag, I don't want to recompile.

I'm running wayland so I cannot use X11 based solutions


Solution

  • I had trouble finding resources so here is what ended up working by adding in ~/.vimrc.

    nnoremap <C-@> :call system("wl-copy", @")<CR>
    

    wl-copy is a Command-line copy/paste utilities for Wayland and it will copy the piped content you give it to system clipboard.

    What mapping above achieves is

    1. Activate the mapping with Ctrl + @. or choose any convenient key combo
      • nnoremap <C-@>
    2. take the contents of the " register,

      • denoted by the @" argument
    3. and pipe contents of @" as an argument to the system wl-copy function

      • shown by :call system("wl-copy", @").

    Alternatively

    Assuming you only want to copy line sections of the file, do shift+v to go into visual mode and only highlight the lines I want to copy. Then do.

    :'<,'>w !wl-copy
    

    where

    You can map that with

    xnoremap <silent> <C-@> :w !wl-copy<CR><CR>