dotfiles/nvim/lua/config/autocmd.lua

36 lines
753 B
Lua
Raw Normal View History

2024-01-23 22:23:58 +01:00
local group = vim.api.nvim_create_augroup('UserGroup', {})
-- Remove trailing whitespace on write
vim.api.nvim_create_autocmd('BufWritePre', {
2024-06-13 21:48:16 +02:00
group = group,
pattern = '*',
callback = function()
if vim.bo.filetype == 'markdown' then return end
vim.cmd [[%s/\s\+$//e]]
end
2024-01-23 22:23:58 +01:00
})
-- Highlight yank
vim.api.nvim_create_autocmd('TextYankPost', {
2024-06-13 21:48:16 +02:00
group = group,
pattern = '*',
callback = function()
vim.highlight.on_yank { timeout = 250 }
end
2024-01-23 22:23:58 +01:00
})
-- Restore cursor position
vim.api.nvim_create_autocmd('BufReadPost', {
2024-06-13 21:48:16 +02:00
group = group,
callback = function(args)
if
vim.fn.line [['"]] >= 1 and
vim.fn.line [['"]] < vim.fn.line '$' and
vim.b[args.buf].filetype ~= 'commit'
then
vim.cmd [[normal! g`"]]
end
end
2024-01-23 22:23:58 +01:00
})