This commit is contained in:
sankalp committed 2025-01-04 21:09:50 +05:45
1 parent ed7544a334
commit d3f7373801
7 files changed
+66 -24

No files matched your search

+25 -2
View File
@@ -1,5 +1,5 @@
local function augroup(name)
return vim.api.nvim_create_augroup('nvim2k_' .. name, { clear = true })
return vim.api.nvim_create_augroup('nvim' .. name, { clear = true })
end
-- Strip trailing spaces before write
@@ -119,8 +119,31 @@ enable_autoformat()
vim.api.nvim_create_user_command('WriteNoFormat', function()
-- Temporarily disable the autoformat autocmd
vim.api.nvim_del_augroup_by_name('nvim2k_autoformat')
vim.api.nvim_del_augroup_by_name('nvim_autoformat')
vim.cmd('write')
-- Re-enable the autoformat autocmd
enable_autoformat()
end, {})
-- Toggle between relative/absolute line numbers
local numbertoggle = augroup('numbertoggle')
vim.api.nvim_create_autocmd({ 'BufEnter', 'FocusGained', 'InsertLeave', 'CmdlineLeave', 'WinEnter' }, {
pattern = '*',
group = numbertoggle,
callback = function()
if vim.o.nu and vim.api.nvim_get_mode().mode ~= 'i' then
vim.opt.relativenumber = true
end
end,
})
vim.api.nvim_create_autocmd({ 'BufLeave', 'FocusLost', 'InsertEnter', 'CmdlineEnter', 'WinLeave' }, {
pattern = '*',
group = numbertoggle,
callback = function()
if vim.o.nu then
vim.opt.relativenumber = false
vim.cmd.redraw()
end
end,
})