From 4b4a1dbf38c6366798f8c8494f6143b615b20694 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Sun, 7 Apr 2024 18:38:20 +0100 Subject: [PATCH] Cleanup :Rename implementation --- lua/commands.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lua/commands.lua b/lua/commands.lua index 13a23e3..de4408e 100644 --- a/lua/commands.lua +++ b/lua/commands.lua @@ -54,21 +54,21 @@ end, { bang = true }) -- :Rename the file associated with current buffer vim.api.nvim_create_user_command('Rename', function(opts) - local from = vim.fn.expand('%') - local buffer = vim.api.nvim_get_current_buf() - local to = nil + local source = vim.fn.expand('%') + local dest = nil local dir = vim.fn.expand('%:h') if dir == '.' then - to = opts.args + dest = opts.args else - to = dir .. '/' .. opts.args + dest = vim.fn.resolve(dir .. '/' .. opts.args) end - vim.loop.fs_rename(from, to, function(err, success) + local buffer = vim.api.nvim_get_current_buf() + vim.loop.fs_rename(source, dest, function(err, success) if not success then error(err) else vim.schedule(function() - vim.cmd('edit ' .. to) + vim.cmd.edit(dest) vim.api.nvim_buf_delete(buffer, {}) end) end