Skip to content

Moving files #2287

Closed
Closed

Description

@aneshodza

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 to something/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.

Activity

  1. j-ole commented on Jun 22, 2023

    @j-ole

    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
  2. aneshodza commented on Jun 22, 2023

    @aneshodza
    Author

    But this is still a copy (it doesn't remove the old location). This function does a cp, instead of an mv
    Now:

    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?

  3. j-ole commented on Jun 22, 2023

    @j-ole

    removing the '-R' flag works

  4. aneshodza commented on Jun 22, 2023

    @aneshodza
    Author

    But cp is still a copy. I'm talking about having a built in move_file_to. Maybe by just copying and slightly changing copy_file_to.

  5. j-ole commented on Jun 22, 2023

    @j-ole

    yes you can rename the function. I've updated the snippet.

  6. aneshodza commented on Jun 22, 2023

    @aneshodza
    Author

    Alright, thanks! Im wondering why this isn't in per default.

  7. alex-courtis commented on Jun 25, 2023

    @alex-courtis
    Member

    Many thanks @joelpeapen

  8. locked and limited conversation to collaborators on Jun 25, 2023
  9. converted this issue into a discussion #2292 on Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions