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
).
<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 tryvnoremap <Leader>c <Cmd>!xsel<CR>
on my setup the mapping works. Also it is probable that you want to usexmap
instead ofvmap
for your mapping. – statox Jul 22 '20 at 11:33vnoremap <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 '20 at 23:21