From a27a21d57e6611aada7fef8b752ac4bb1e04d334 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 15 Oct 2023 23:26:11 +0200 Subject: Yank to clipboard in termux --- lua/user/opts.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lua') diff --git a/lua/user/opts.lua b/lua/user/opts.lua index 3bf5b37..3bf82c7 100644 --- a/lua/user/opts.lua +++ b/lua/user/opts.lua @@ -319,3 +319,33 @@ vim.cmd([[ let &scrollback=s:scroll_value endfunction ]]) + +-- Yank to clipboard in termux +if vim.fn.has('termux') == 1 then + local Job = require('plenary.job') + vim.api.nvim_create_autocmd('TextYankPost', { + pattern = '*', + callback = function() + Job:new({ + command = 'termux-clipboard-set', + writer = vim.fn.getreg('@'), + }):start() + end, + }) +end + +function GetTermuxClipboard() + if vim.fn.has('termux') == 1 then + local sysclip = vim.fn.system('termux-clipboard-get') + if sysclip ~= '@' then + vim.fn.setreg('@', sysclip) + end + end + return '' +end + +if vim.fn.has('termux') == 1 then + vim.cmd('autocmd TextYankPost * call GetTermuxClipboard()') + vim.cmd('noremap p Paste("p")') + vim.cmd('noremap P Paste("P")') +end -- cgit v1.2.3