From 04b5e6e4fb586cd2a2ac9b8a1c9cebc22215b5fa Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Sun, 7 Apr 2024 18:38:43 +0100 Subject: [PATCH] Add :Move command to move files around --- lua/commands.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lua/commands.lua b/lua/commands.lua index de4408e..24227d5 100644 --- a/lua/commands.lua +++ b/lua/commands.lua @@ -50,7 +50,26 @@ vim.api.nvim_create_user_command('Remove', function(opts) vim.loop.fs_unlink(path, callback) end, { bang = true }) --- TODO: :Move +-- :Move the file associated with the current buffer +vim.api.nvim_create_user_command('Move', function(opts) + local source = vim.fn.expand('%:p') + local dest = opts.args + if vim.fn.isdirectory(dest) ~= 0 then + dest = vim.fn.resolve(dest .. '/' .. vim.fn.expand('%:t')) + end + vim.loop.fs_rename(source, dest, function(err, success) + if success then + vim.schedule(function() + vim.cmd.edit(dest) + end) + else + error(err) + end + end) +end, { + nargs = 1, + complete = 'file', +}) -- :Rename the file associated with current buffer vim.api.nvim_create_user_command('Rename', function(opts)