TransWikia.com

doesn't seem to work in visual mode

Vi and Vim Asked on November 22, 2021

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?

One Answer

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).

Answered by Matt on November 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP