Cleanup :Rename implementation
This commit is contained in:
parent
d92a312992
commit
4b4a1dbf38
@ -54,21 +54,21 @@ end, { bang = true })
|
|||||||
|
|
||||||
-- :Rename the file associated with current buffer
|
-- :Rename the file associated with current buffer
|
||||||
vim.api.nvim_create_user_command('Rename', function(opts)
|
vim.api.nvim_create_user_command('Rename', function(opts)
|
||||||
local from = vim.fn.expand('%')
|
local source = vim.fn.expand('%')
|
||||||
local buffer = vim.api.nvim_get_current_buf()
|
local dest = nil
|
||||||
local to = nil
|
|
||||||
local dir = vim.fn.expand('%:h')
|
local dir = vim.fn.expand('%:h')
|
||||||
if dir == '.' then
|
if dir == '.' then
|
||||||
to = opts.args
|
dest = opts.args
|
||||||
else
|
else
|
||||||
to = dir .. '/' .. opts.args
|
dest = vim.fn.resolve(dir .. '/' .. opts.args)
|
||||||
end
|
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
|
if not success then
|
||||||
error(err)
|
error(err)
|
||||||
else
|
else
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.cmd('edit ' .. to)
|
vim.cmd.edit(dest)
|
||||||
vim.api.nvim_buf_delete(buffer, {})
|
vim.api.nvim_buf_delete(buffer, {})
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user