Replies: 8 comments
-
It's on the wiki: https://github.com/nvim-tree/nvim-tree.lua/wiki/Recipes#nerdtree-style-copy-file-to local function on_attach(bufnr)
...
local function move_file_to()
local node = api.tree.get_node_under_cursor()
local file_src = node['absolute_path']
local file_out = vim.fn.input("MOVE TO: ", file_src, "file")
local dir = vim.fn.fnamemodify(file_out, ":h")
vim.fn.system { 'mkdir', '-p', dir }
vim.fn.system { 'mv', file_src, file_out }
end
vim.keymap.set('n', 'X', move_file_to, opts('Move File To'))
end |
Beta Was this translation helpful? Give feedback.
-
But this is still a copy (it doesn't remove the old location). This function does a vim.fn.system { 'cp', '-R', file_src, file_out } To move: vim.fn.system { 'mv', '-R', file_src, file_out } But the message I'm getting from this, is that the lack of a move is a design choice? |
Beta Was this translation helpful? Give feedback.
-
removing the |
Beta Was this translation helpful? Give feedback.
-
But |
Beta Was this translation helpful? Give feedback.
-
yes you can rename the function. I've updated the snippet. |
Beta Was this translation helpful? Give feedback.
-
Alright, thanks! Im wondering why this isn't in per default. |
Beta Was this translation helpful? Give feedback.
-
Many thanks @joelpeapen |
Beta Was this translation helpful? Give feedback.
-
One more question about this solution... If I rename a file I get a nice "in place" popup where I can type the name. Is it possible to use such a popup for this custom function as well @joelpeapen? |
Beta Was this translation helpful? Give feedback.
-
I saw that there is no "move" function on nvim-tree. Was that an oversight from me, or is there really no move?
Can this functionality be implemented utilising API?
It should be possible, as we can already cut and paste.
Is your feature request related to a problem? Please describe.
I wanted to move a file from
something/else/file.lua
tosomething/file.lua
. You can achieve that by cutting and pasting, but why not have both in one step.Describe the solution you'd like
Just a move function. The window for moving it to somewhere else could look the same as the rename but also show the path that can be altered.
Beta Was this translation helpful? Give feedback.
All reactions