Browse Source

load termux-clipboard plugin only if TERMUX_API_VERSION set and us termux-clipboard-set for RegisterSwapDefaultWith() when register is '+'

Daniel Sheffield 1 week ago
parent
commit
54ec36784d
2 changed files with 11 additions and 2 deletions
  1. 1 1
      vim/vimfiles/plugin/termux/termux-clipboard.vim
  2. 10 1
      vim/vimfiles/vimrc

+ 1 - 1
vim/vimfiles/plugin/termux/termux-clipboard.vim

@@ -16,7 +16,7 @@
 
 ""
 " Fast finish if already loaded or Vim version is bellow target
-if exists('g:termux_clipboard__loaded') || v:version < 700
+if exists('g:termux_clipboard__loaded') || v:version < 700 || $TERMUX_API_VERSION == ''
 	finish
 endif
 let g:termux_clipboard__loaded = 1

+ 10 - 1
vim/vimfiles/vimrc

@@ -105,7 +105,16 @@ nnoremap <LEADER>gid :read !date +\%Y-\%m-\%d<CR>kJ
 function! RegisterSwapDefaultWith()
     " Swap the default register with the contents of another
     let l = nr2char(getchar())
-    execute 'let @x=@' . l . '| let @' . l . '=@" | let @"=@x'
+    if exists('g:termux_clipboard__loaded') && l == '+'
+        silent call job_start(['termux-clipboard-set'] + [getreg('')], {
+            \ 	"in_io": "null",
+            \ 	"out_io": "null",
+            \ 	"err_io": "null",
+            \ 	"stoponexit": "",
+            \ })
+    else
+        execute 'let @x=@' . l . '| let @' . l . '=@" | let @"=@x'
+    endif
 endfunction
 nnoremap <Leader>c :call RegisterSwapDefaultWith()<CR>
 nnoremap <Leader>C :call RegisterSwapDefaultWith()<CR>+