Code Monkey home page Code Monkey logo

Comments (8)

kiyoon avatar kiyoon commented on August 13, 2024 2

Finally made it work. I just had to remap all put keys so it uses all plugins together.

The configuration below integrates tmux.nvim with yanky.nvim and which-key.nvim so we get the benefits of all yank-related plugins.

From the dotfiles here

require("tmux").setup {
  copy_sync = {
    enable = true,
    sync_clipboard = false,
    sync_registers = true,
  },
  resize = {
    enable_default_keybindings = false,
  },
}

-- since we want to use sync_registers with yanky.nvim, we need to
-- configure keybindings manually.
local yanky = require "yanky"
yanky.setup {
  highlight = {
    on_put = true,
    on_yank = true,
    timer = 300,
  },
}
vim.keymap.set("n", "p", function()
  if vim.env.TMUX then
    require("tmux.copy").sync_registers()
  end
  yanky.put("p", false)
end)
vim.keymap.set("x", "p", function()
  if vim.env.TMUX then
    require("tmux.copy").sync_registers()
  end
  yanky.put("p", true)
end)
vim.keymap.set("n", "P", function()
  if vim.env.TMUX then
    require("tmux.copy").sync_registers()
  end
  yanky.put("P", false)
end)
vim.keymap.set("x", "P", function()
  if vim.env.TMUX then
    require("tmux.copy").sync_registers()
  end
  yanky.put("P", true)
end)

local status, which_key = pcall(require, "which-key")
if status then
  vim.keymap.set("n", [["]], function()
    if vim.env.TMUX then
      require("tmux.copy").sync_registers()
    end
    which_key.show('"', { mode = "n", auto = true })
  end)
  vim.keymap.set("x", [["]], function()
    if vim.env.TMUX then
      require("tmux.copy").sync_registers()
    end
    which_key.show('"', { mode = "v", auto = true })
  end)
end
vim.keymap.set("n", "<c-n>", "<Plug>(YankyCycleForward)")
vim.keymap.set("n", "<c-p>", "<Plug>(YankyCycleBackward)")
vim.keymap.set({ "n", "x" }, "y", "<Plug>(YankyYank)")
vim.keymap.set("n", "=p", "<Plug>(YankyPutAfterFilter)")
vim.keymap.set("n", "=P", "<Plug>(YankyPutBeforeFilter)")
require("telescope").load_extension "yank_history"

from tmux.nvim.

kiyoon avatar kiyoon commented on August 13, 2024 1

Heho,

unfortunately the plugin needs todo both because the sync from tmux has to run right before the paste takes place. There are no events from tmux buffer to know when new values arrive. If you find another solution im happy to try it.

I'll leave this issue open in case someone can contribute to this behaviour.

Kind regards Alexander

I see, the problem was in pasting. It's a pity neovim doesn't have TextPastePre or something like that.. Thanks for your awesome work though!

from tmux.nvim.

moetayuko avatar moetayuko commented on August 13, 2024 1

After recent refactoring of which-key.nvim 3.x, the which-key.nvim integration provided by @kiyoon is no longer applicable due to a bugfix.

Fortunately, folke provided a much easier approach at folke/which-key.nvim#743 (comment) which directly injects sync_registers() into the corresponding lua method and does not require messing with keymaps.

Similarly, I re-implemented yanky.nvim integration to eliminate the need to set keymaps. Below is my config for LazyVim:

return {
  {
    "aserowy/tmux.nvim",
    event = "VeryLazy",
    opts = {
      copy_sync = {
        enable = true,
        sync_registers_keymap_put = false, -- remove this line if you don't use yanky.nvim
        sync_registers_keymap_reg = false,
      },
    },
    config = function(_, opts)
      require("tmux").setup(opts)
      if vim.env.TMUX then
        LazyVim.on_load("which-key.nvim", function()
          local reg = require("which-key.plugins.registers")
          local expand = reg.expand
          function reg.expand()
            require("tmux.copy").sync_registers()
            return expand()
          end
        end)

        if LazyVim.has("yanky.nvim") then
          LazyVim.on_load("yanky.nvim", function()
            local yanky = require("yanky")
            local put = yanky.put
            function yanky.put(type, is_visual, callback)
              require("tmux.copy").sync_registers()
              return put(type, is_visual, callback)
            end
          end)
        end
      end
    end,
  },
}

from tmux.nvim.

aserowy avatar aserowy commented on August 13, 2024

Heho,

unfortunately the plugin needs todo both because the sync from tmux has to run right before the paste takes place. There are no events from tmux buffer to know when new values arrive. If you find another solution im happy to try it.

I'll leave this issue open in case someone can contribute to this behaviour.

Kind regards
Alexander

from tmux.nvim.

kiyoon avatar kiyoon commented on August 13, 2024

Hi, is it maybe possible to add a configuration that allows custom paste function?

I'm trying to integrate yanky.nvim with this plugin together, and I think it can be possible if yanky paste function is called after sync_register.

I think it will be sick if it allows that. Thanks!

from tmux.nvim.

aserowy avatar aserowy commented on August 13, 2024

nice! i pinned your solution to let others find it.

from tmux.nvim.

catgoose avatar catgoose commented on August 13, 2024

I solved my problem with sharing clipboard by using the ojroques/nvim-osc52 plugin:

Using lazy.nvim.
This is my yanky.lua:

local opts = {
	ring = {
		history_length = 1000,
		storage = "shada",
		sync_with_numbered_registers = true,
	},
	system_clipboard = {
		sync_with_ring = true,
	},
	highlight = {
		on_put = true,
		on_yank = true,
		timer = 500,
	},
	preserve_cursor_position = {
		enabled = true,
	},
}

return {
	"gbprod/yanky.nvim",
	opts = opts,
	keys = {
		{ "y", "<Plug>(YankyYank)", mode = { "n", "x" } },
		{ "p", "<Plug>(YankyPutAfter)", mode = { "n", "x" } },
		{ "P", "<Plug>(YankyPutBefore)", mode = { "n", "x" } },
		{ "gP", "<Plug>(YankyGPutBefore)", mode = { "n", "x" } },
		{ "gp", "<Plug>(YankyGPutAfter)", mode = { "n", "x" } },
		{ "<c-p>", "<Plug>(YankyCycleForward)" },
		{ "<c-n>", "<Plug>(YankyCycleBackward)" },
		{ "<leader>pp", "<cmd>YankyRingHistory<cr>" },
	},
	event = "BufReadPre",
}

tmux.lua:

local opts = {
	copy_sync = {
		enable = false,
	},
	navigation = {
		cycle_navigation = true,
		enable_default_keybindings = true,
		persist_zoom = true,
	},
	resize = {
		enable_default_keybindings = false,
		resize_step_x = 1,
		resize_step_y = 1,
	},
}

return {
	"aserowy/tmux.nvim",
	event = "BufReadPre",
	opts = opts,
}

osc52.lua:

local api, v = vim.api, vim.v

local opts = {
	silent = true,
}

return {
	"ojroques/nvim-osc52",
	event = "BufReadPre",
	opts = opts,
	init = function()
		local au_copy = function()
			if v.event.operator == "y" and v.event.regname == "+" then
				require("osc52").copy_register("+")
			end
			if v.event.operator == "y" and v.event.regname == "" then
				require("osc52").copy_register("")
			end
		end
		api.nvim_create_autocmd("TextYankPost", { callback = au_copy })
	end,
}

I don't have to use special callbacks and my clipboard is shared between the host OS over ssh, neovim, and tmux.

from tmux.nvim.

aserowy avatar aserowy commented on August 13, 2024

Thus, ill let it pinned.

from tmux.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.