Open otavioschwanck opened 2 years ago
nvim-tree does not use the system clipboard.
An optional protocol could be developed that uses system clipboard. Something like:
nvim-tree: /path/to/file1, /path/to/file2
This would cause strange results when pasting the clipboard anywhere outside of nvim-tree, and files copied outside of nvim-tree could not be pasted in nvim-tree.
It is highly unlikely that this functionality will be built or accepted.
it could be an optional feature that could be enabled, i really dont care about the system clipboard, even the filebrowser from the OS works in this way, and also, nvim-tree could save on a pre-defined register (i think it is shared between vim instances)
What is the pre-defined register? clipboard register is only shared. The other registers are not shared.
What is the pre-defined register? clipboard register is only shared. The other registers are not shared.
you are right!
But it could save on a tmp file
But it could save on a tmp file
That is a viable solution.
One can obtain current file name by using expand("%:p")
builtin. Then, when copied into a register (clipboard) you can copy it via commandline terminal:
" In vim commandline
:echo setreg("", expand("%:p"))
" Switch to another window
:!cp ...<ctrl+v> ./
But it could save on a tmp file
That is a viable solution.
@alex-courtis You are better to keep track of a file path, rather than copying it somehwere temporarily.
We already have gy
to copy the absolute path. What if we had something like gp
to paste from the absolute path?
The second step could be to use m
to mark multiple files, then go bgy
to copy all absolute paths with \n
delimiter and make gp
be capable of pasting from multiple paths.
What do you think?
We already have
gy
to copy the absolute path. What if we had something likegp
to paste from the absolute path?
That's an interesting idea - using absolute paths rather than the "internal clipboard". The question remains: where do these paths come from? The "
or +
register?
The second step could be to use m to mark multiple files, then go bgy to copy all absolute paths with \n delimiter and make gp be capable of pasting from multiple paths.
Could we not simplify this to something like: m
, bcp
?
We already have
gy
to copy the absolute path. What if we had something likegp
to paste from the absolute path?That's an interesting idea - using absolute paths rather than the "internal clipboard". The question remains: where do these paths come from? The
"
or+
register?I'd say they should act the same way as
gy
currently does, i. e. based on user settings:local function copy_to_clipboard(content) if M.use_system_clipboard == true then vim.fn.setreg("+", content) vim.fn.setreg('"', content) return notify.info(string.format("Copied %s to system clipboard!", content)) else vim.fn.setreg('"', content) vim.fn.setreg("1", content) return notify.info(string.format("Copied %s to neovim clipboard!", content)) end end
The second step could be to use m to mark multiple files, then go bgy to copy all absolute paths with \n delimiter and make gp be capable of pasting from multiple paths.
Could we not simplify this to something like:
m
,bcp
?That could work too. I just like
bgy
as I personally find it easier to remember as a variant ofgy
that works with bookmarks. Also, since bothgy
andbgy
could potentially work withgp
interchangeably for single file or multiple files, it would be less confusing to have similar commands maybe. I don't have a strong opinion here though.
Hi, finally, is this possible? This would be such a useful utility, open vertical tmux pane, open another git project, and then copy files from one project to another like in vscode
This has not been implemented however we do have the bones of a solution here.
Pull Requests are most gratefully appreciated.
This is nowhere PR ready, but maybe someone will find this useful or flesh it out into a PR:
vim.api.nvim_create_autocmd('filetype', {
pattern = 'NvimTree',
desc = 'Mappings for NvimTree',
callback = function()
-- Yank marked files
vim.keymap.set('n', 'bgy',
function()
local api = require 'nvim-tree.api'
local marks = api.marks.list()
if #marks == 0 then
print('No items marked')
return
end
local absolute_file_paths = ''
for _, mark in ipairs(marks) do
absolute_file_paths = absolute_file_paths .. mark.absolute_path .. '\n'
end
-- Using system registers for multi-instance support.
vim.fn.setreg("+", absolute_file_paths)
print('Yanked ' .. #marks .. ' items')
end,
{ remap = true, buffer = true })
-- Paste files
vim.keymap.set('n', 'gp',
function()
local api = require 'nvim-tree.api'
local source_paths = {}
for path in vim.fn.getreg('+'):gmatch('[^\n%s]+') do
source_paths[#source_paths + 1] = path
end
local node = api.tree.get_node_under_cursor()
local is_folder = node.fs_stat and node.fs_stat.type == 'directory' or false
local target_path = is_folder and node.absolute_path or
vim.fn.fnamemodify(node.absolute_path, ":h")
for _, source_path in ipairs(source_paths) do
vim.fn.system { 'cp', '-R', source_path, target_path }
end
api.tree.reload()
print('Pasted ' .. #source_paths .. ' items')
end,
{ remap = true, buffer = true })
end
})
Nice work! The concept is proven.
"
+
does indeed seem the best solution.
if not M.config.filesystem_watchers.enable then
around the reloadcopy-paste.lua
could be reused, with the fsstat and vim.loop.fs_copyfile
etc.This can be added everywhere - copy/cut as well as bulk
Hi @alex-courtis is this planned to be added? I am currently using the snippet code from @lawrence-laz and it works really well
Pull Requests are always most gratefully appreciated.
i use use neovim instance for each of projects of mine. sometimes i want to copy file from one to another and its really hard to do with nvim-tree clipboard working only current instance