nvim/lua/core/autocmds.lua

91 lines
2.3 KiB
Lua
Raw Normal View History

2025-02-14 01:48:45 -08:00
local augroup = vim.api.nvim_create_augroup
local autocmd = vim.api.nvim_create_autocmd
-- {{{ Restore cursor position
2025-02-14 17:34:12 -08:00
local restore_cursor = augroup("RestoreCursor", { clear = true })
autocmd("BufReadPost", {
group = restore_cursor,
callback = function()
local mark = vim.api.nvim_buf_get_mark(0, '"')
local lcount = vim.api.nvim_buf_line_count(0)
if mark[1] > 0 and mark[1] <= lcount then
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end,
2025-02-14 01:48:45 -08:00
})
-- }}}
2025-02-14 01:48:45 -08:00
-- {{{ Open help and man in vertical split
2025-02-14 17:34:12 -08:00
local help_config = augroup("HelpConfig", { clear = true })
autocmd("FileType", {
group = help_config,
pattern = { "help", "man" },
command = "wincmd L",
2025-02-14 01:48:45 -08:00
})
-- }}}
2025-02-14 01:48:45 -08:00
-- {{{ set term options
2025-02-14 17:34:12 -08:00
local term_config = augroup("TermConfig", { clear = true })
autocmd("TermOpen", {
group = term_config,
pattern = "*",
command = "setlocal nonumber norelativenumber",
2025-02-14 01:48:45 -08:00
})
-- }}}
2025-02-14 01:48:45 -08:00
-- {{{ Highlight yanked text
2025-02-14 17:34:12 -08:00
local highlight_yank = augroup("HighlightYank", { clear = true })
autocmd("TextYankPost", {
group = highlight_yank,
pattern = "*",
callback = function()
vim.highlight.on_yank({ higroup = "IncSearch", timeout = 420 })
end,
2025-02-14 01:48:45 -08:00
})
-- }}}
2025-02-14 01:48:45 -08:00
-- {{{ Disable indent-blankline for dashboard
2025-02-14 17:34:12 -08:00
function disable_for_dashboard()
local buftype = vim.api.nvim_buf_get_option(0, "buftype")
local filetype = vim.api.nvim_buf_get_option(0, "filetype")
if buftype == "nofile" and filetype == "dashboard" then
vim.b.indent_blankline_enabled = false
end
end
vim.cmd([[
augroup IndentBlankline
autocmd!
autocmd FileType dashboard lua disable_for_dashboard()
augroup END
]])
-- }}}
2025-02-14 17:34:12 -08:00
-- {{{ Code companion hook
local group = vim.api.nvim_create_augroup("CodeCompanionHooks", {})
2025-02-15 01:17:09 -08:00
vim.api.nvim_create_autocmd({ "User" }, {
pattern = "CodeCompanionInline*",
group = group,
callback = function(request)
if request.match == "CodeCompanionInlineFinished" then
-- Format the buffer after the inline request has completed
require("conform").format({ bufnr = request.buf })
end
2025-02-15 01:17:09 -08:00
end,
})
-- }}}
2025-02-20 04:18:32 -08:00
-- {{{ Hyprlang LSP
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
pattern = { "*.hl", "hypr*.conf" },
callback = function(event)
print(string.format("starting hyprls for %s", vim.inspect(event)))
vim.lsp.start({
name = "hyprlang",
cmd = { "hyprls" },
root_dir = vim.fn.getcwd(),
})
end,
})
--}}}