Compare commits
2 Commits
d92a312992
...
04b5e6e4fb
Author | SHA1 | Date | |
---|---|---|---|
04b5e6e4fb | |||
4b4a1dbf38 |
@ -50,25 +50,44 @@ 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)
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user