This is an automated archive made by the Lemmit Bot.

The original was posted on /r/neovim by /u/santhosh-tekuri on 2025-06-06 14:29:14+00:00.


vim.api.nvim_create_autocmd('FocusLost', {
    desc = "Copy to clipboard on FocusLost",
    callback = function()
        vim.fn.setreg("+", vim.fn.getreg("0"))
    end,
})

if you are using tmux you should enable focus-events:

set -g focus-events on

earlier I used to use <leader>y to copy to clipboard. but the above trick seems cleaner