nvim/lua/commands.lua

32 lines
1.0 KiB
Lua

-- :TabWidth <N> set the tab width for the current buffer
vim.api.nvim_create_user_command('TabWidth', function(opts)
-- Set the tab width for the current filetype
-- FIXME: Doesn't seem to cover all bases in neovim when editorconfig is
-- involved, specifically with pressing o/O in C++ from a line with a brace.
-- This might be related to tree-sitter indentation? Or could be that I've
-- not ported over all my filetype settings yet.
local width = tonumber(opts.args)
vim.opt.tabstop = width
vim.opt.shiftwidth = width
vim.opt.softtabstop = width
end, { nargs = 1 })
-- TODO: :Rename
-- vim.loop.fs_rename
-- :Remove the file associated with the current buffer, then delete the buffer
vim.api.nvim_create_user_command('Remove', function()
local path = vim.fn.expand('%:p')
vim.loop.fs_unlink(path, function(err, success)
if success then
vim.schedule(function()
vim.api.nvim_buf_delete(vim.api.nvim_get_current_buf(), {})
end)
else
error(err)
end
end)
end, {})
-- TODO: :Move