mirror of
https://github.com/harivansh-afk/nvim.git
synced 2026-04-15 07:04:47 +00:00
38 lines
1.1 KiB
Lua
38 lines
1.1 KiB
Lua
-- Autocommands
|
|
local api = vim.api
|
|
local augroup = api.nvim_create_augroup("UserAutocmds", { clear = true })
|
|
|
|
-- Highlight on yank
|
|
api.nvim_create_autocmd("TextYankPost", {
|
|
group = augroup,
|
|
callback = function()
|
|
vim.highlight.on_yank({ higroup = "Visual", timeout = 200 })
|
|
end,
|
|
desc = "Highlight text on yank",
|
|
})
|
|
|
|
-- Restore cursor position on file open
|
|
api.nvim_create_autocmd("BufReadPost", {
|
|
group = augroup,
|
|
callback = function()
|
|
local excluded = { gitcommit = true, gitrebase = true }
|
|
if excluded[vim.bo.filetype] then return end
|
|
local mark = api.nvim_buf_get_mark(0, '"')
|
|
local line_count = api.nvim_buf_line_count(0)
|
|
if mark[1] > 0 and mark[1] <= line_count then
|
|
pcall(api.nvim_win_set_cursor, 0, mark)
|
|
end
|
|
end,
|
|
desc = "Restore cursor position",
|
|
})
|
|
|
|
-- Auto-resize splits on VimResized
|
|
api.nvim_create_autocmd("VimResized", {
|
|
group = augroup,
|
|
callback = function()
|
|
local current_tab = vim.fn.tabpagenr()
|
|
vim.cmd("tabdo wincmd =")
|
|
vim.cmd("tabnext " .. current_tab)
|
|
end,
|
|
desc = "Auto-resize splits",
|
|
})
|