Compare commits
No commits in common. "04b5e6e4fb586cd2a2ac9b8a1c9cebc22215b5fa" and "d92a3129929751e8a7801446ec6382b6fb243689" have entirely different histories.
04b5e6e4fb
...
d92a312992
@ -50,44 +50,25 @@ vim.api.nvim_create_user_command('Remove', function(opts)
|
|||||||
vim.loop.fs_unlink(path, callback)
|
vim.loop.fs_unlink(path, callback)
|
||||||
end, { bang = true })
|
end, { bang = true })
|
||||||
|
|
||||||
-- :Move the file associated with the current buffer
|
-- TODO: :Move
|
||||||
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
|
-- :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 source = vim.fn.expand('%')
|
local from = vim.fn.expand('%')
|
||||||
local dest = nil
|
local buffer = vim.api.nvim_get_current_buf()
|
||||||
|
local to = nil
|
||||||
local dir = vim.fn.expand('%:h')
|
local dir = vim.fn.expand('%:h')
|
||||||
if dir == '.' then
|
if dir == '.' then
|
||||||
dest = opts.args
|
to = opts.args
|
||||||
else
|
else
|
||||||
dest = vim.fn.resolve(dir .. '/' .. opts.args)
|
to = dir .. '/' .. opts.args
|
||||||
end
|
end
|
||||||
local buffer = vim.api.nvim_get_current_buf()
|
vim.loop.fs_rename(from, to, function(err, success)
|
||||||
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(dest)
|
vim.cmd('edit ' .. to)
|
||||||
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