copy to android system clipboard in nvim from termux

770 views Asked by At

I use neovim on termux on android 11 i commonly use :y to yank/copy text to nvim clipboard

then paste it to another files

recently I've tried using helix-editor(hx) looks and feels so similar to neovim(with nvchad/spacevim) with a bunch of themes

in its normal mode there is a command :clipboard-yank which literally Yank main selection into system clipboard. after selection of required text.

and similar function is also available on tmux too..

but in nvim it doesn't copy to system clipboard

i tried searching for this function and fond some solutions but those didnt worked for me

set clipboard=unnamed
set clipboard=unnamedplus
set clipboard+=unnamed

or these "*y "+y

so, is thre any way to copy to system clipboard

2

There are 2 answers

0
SergioAraujo On

I had the same problem. Install termux-api and you will have termux-clipboard-get and termux-clipboard-set. I also had to uninstall xclip

If you run :h clipboard you will get:

                                  *clipboard-tool*
The presence of a working clipboard tool implicitly enables the '+' and '*'
registers. Nvim looks for these clipboard tools, in order of priority:

  - |g:clipboard|
  - pbcopy, pbpaste (macOS)
  - wl-copy, wl-paste (if $WAYLAND_DISPLAY is set)
  - waycopy, waypaste (if $WAYLAND_DISPLAY is set)
  - xclip (if $DISPLAY is set)
  - xsel (if $DISPLAY is set)
  - lemonade (for SSH) https://github.com/pocke/lemonade
  - doitclient (for SSH) https://www.chiark.greenend.org.uk/~sgtatham/doit/
  - win32yank (Windows)
  - termux (via termux-clipboard-set, termux-clipboard-set)
  - tmux (if $TMUX is set)

All you have to do is make sure you have termux-clipboard and remove xclip

0
echo On

see here this actually works

  • install termux-api
  • also in termux pkg install termux-api
  • test it: termux-clipboard-set "text" and termux-clipboard-get
  • add this line to your .vimrc or init.vim : set clipboard+=unnamedplus