diff --git a/README.md b/README.md index 6cbf98e9..3c1a0cdf 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS timeout = 400, }, actions = { + use_system_clipboard = true, change_dir = { enable = true, global = false, diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index cf2b677d..a6ceddf7 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -146,6 +146,7 @@ function. timeout = 400, }, actions = { + use_system_clipboard = true, change_dir = { enable = true, global = false, @@ -479,6 +480,13 @@ Here is a list of the options available in the setup call: `filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame", },` `buftype = { "nofile", "terminal", "help", }` `}` + + - |actions.use_system_clipboard|: A boolean value that toggle the use of system clipboard + when copy/paste function are invoked. + When enabled, copied text will be stored in registers '+' (system), otherwise, it will be stored in '1' and '"'. + type: `boolean` + default: `true` + *nvim-tree.log* |log|: configuration for diagnostic logging diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 466f9f84..b87f0669 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -371,6 +371,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS timeout = 400, }, actions = { + use_system_clipboard = true, change_dir = { enable = true, global = false, diff --git a/lua/nvim-tree/actions/copy-paste.lua b/lua/nvim-tree/actions/copy-paste.lua index 11e9af60..7247ddc8 100644 --- a/lua/nvim-tree/actions/copy-paste.lua +++ b/lua/nvim-tree/actions/copy-paste.lua @@ -212,9 +212,15 @@ function M.print_clipboard() end local function copy_to_clipboard(content) - vim.fn.setreg("+", content) - vim.fn.setreg('"', content) - return a.nvim_out_write(string.format("Copied %s to system clipboard! \n", content)) + if M.use_sys_clipboard == true then + vim.fn.setreg("+", content) + vim.fn.setreg('"', content) + return a.nvim_out_write(string.format("Copied %s to system clipboard! \n", content)) + else + vim.fn.setreg('"', content) + vim.fn.setreg("1", content) + return a.nvim_out_write(string.format("Copied %s to neovim clipboard \n", content)) + end end function M.copy_filename(node) @@ -234,4 +240,8 @@ function M.copy_absolute_path(node) return copy_to_clipboard(content) end +function M.setup(opts) + M.use_sys_clipboard = opts.actions.use_sys_clipboard +end + return M diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index d049a29a..ab6065a2 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -226,6 +226,7 @@ function M.setup(opts) require("nvim-tree.actions.trash").setup(opts.trash) require("nvim-tree.actions.open-file").setup(opts) require("nvim-tree.actions.change-dir").setup(opts) + require("nvim-tree.actions.copy-paste").setup(opts) local user_map_config = (opts.view or {}).mappings or {} local options = vim.tbl_deep_extend("force", DEFAULT_MAPPING_CONFIG, user_map_config)