Add the :Rename command
This commit is contained in:
parent
c8b6476a2b
commit
e8a420d99d
@ -11,9 +11,6 @@ vim.api.nvim_create_user_command('TabWidth', function(opts)
|
|||||||
vim.opt.softtabstop = width
|
vim.opt.softtabstop = width
|
||||||
end, { nargs = 1 })
|
end, { nargs = 1 })
|
||||||
|
|
||||||
-- TODO: :Rename
|
|
||||||
-- vim.loop.fs_rename
|
|
||||||
|
|
||||||
-- :Remove the file associated with the current buffer, then delete the buffer
|
-- :Remove the file associated with the current buffer, then delete the buffer
|
||||||
vim.api.nvim_create_user_command('Remove', function(opts)
|
vim.api.nvim_create_user_command('Remove', function(opts)
|
||||||
local path = vim.fn.expand('%:p')
|
local path = vim.fn.expand('%:p')
|
||||||
@ -45,3 +42,35 @@ vim.api.nvim_create_user_command('Remove', function(opts)
|
|||||||
end, { bang = true })
|
end, { bang = true })
|
||||||
|
|
||||||
-- TODO: :Move
|
-- TODO: :Move
|
||||||
|
|
||||||
|
-- :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 dir = vim.fn.expand('%:h')
|
||||||
|
if dir == '.' then
|
||||||
|
to = opts.args
|
||||||
|
else
|
||||||
|
to = dir .. '/' .. opts.args
|
||||||
|
end
|
||||||
|
vim.loop.fs_rename(from, to, function(err, success)
|
||||||
|
if not success then
|
||||||
|
error(err)
|
||||||
|
else
|
||||||
|
vim.schedule(function()
|
||||||
|
vim.cmd('edit ' .. to)
|
||||||
|
vim.api.nvim_buf_delete(buffer, {})
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end, {
|
||||||
|
nargs = 1,
|
||||||
|
complete = function()
|
||||||
|
return { vim.fn.expand('%:t') }
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
-- TODO: :Chmod
|
||||||
|
|
||||||
|
-- TODO: :Mkdir
|
||||||
|
Loading…
x
Reference in New Issue
Block a user