1

The following command copies the selected text into the PRIMARY selection:

vnoremap <Leader>c :'<,'>!xsel<CR>u

But this way it doesn't work:

vnoremap <Leader>c <Cmd>'<,'>!xsel<CR>u

The documentation says <Cmd> is generally preferable. What am I doing wrong?

  • 1
    From what I understand from the doc <Cmd> is useful to avoid using :<C-u> to remove the range in your mappings so here I don't thing using <Cmd> is useful for you since you want to keep the '<,'> range. If I try vnoremap <Leader>c <Cmd>!xsel<CR> on my setup the mapping works. Also it is probable that you want to use xmap instead of vmap for your mapping. – statox Jul 22 at 11:33
  • I'm not sure how can vnoremap <Leader>c <Cmd>!xsel<CR> work for you. From me it stays in visual mode, and nothing gets copied into the PRIMARY selection. – x-yuri Jul 22 at 23:21
2

The automatic bookmarks '< and '> get updated only after the Visual mode is left. Hence <Cmd> is not useful for your example, as you effectively apply the previous selection range, not the current one.

You really should use "normal colon"-mapping here:

xnoremap <Leader>c :w !xsel<CR>

Note (1) use xnoremap instead of vnoremap so we don't mess with "Select" modes; (2) don't add "Visual" marks, as they are put in automatically; (3) do :w !xsel to have stdin redirected only, as we don't need xsel's output.

Also note that Neovim is normally able to find xsel/xclip and to set up "plus" and "star" registers without any additional scripting (see :h clipboard-tool).

| improve this answer | |

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.