From e9a2f811b7d030cb8701bd8459fd5c842a521eff Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Tue, 13 May 2025 10:07:17 +0300 Subject: =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20nvim=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nvim/lua/autocommands.lua | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'nvim/lua/autocommands.lua') diff --git a/nvim/lua/autocommands.lua b/nvim/lua/autocommands.lua index f0733f3..48c94d9 100644 --- a/nvim/lua/autocommands.lua +++ b/nvim/lua/autocommands.lua @@ -69,13 +69,6 @@ vim.api.nvim_create_autocmd("TextYankPost", { end, }) -vim.api.nvim_create_autocmd({ "BufReadPost", "FileReadPost" }, { - pattern = "*", - callback = function() - vim.cmd("normal! zR") - end, -}) - vim.api.nvim_create_autocmd("BufEnter", { callback = function() if vim.bo.filetype == "NvimTree" or vim.fn.expand("%") == "" then @@ -92,6 +85,33 @@ vim.api.nvim_create_autocmd("BufEnter", { end, }) +vim.api.nvim_create_autocmd({ "BufEnter", "BufAdd", "BufNew", "BufNewFile", "BufWinEnter" }, { + group = vim.api.nvim_create_augroup("TS_FOLD_WORKAROUND", {}), + callback = function() + vim.opt.foldmethod = "expr" + vim.opt.foldexpr = "nvim_treesitter#foldexpr()" + end, +}) +vim.api.nvim_create_autocmd("FileType", { + pattern = "*", + callback = function(args) + local buf = args.buf + local ft = vim.bo[buf].filetype + + if ft and ft ~= "" then + local has_parser, _ = pcall(vim.treesitter.language.get_lang, ft) + if has_parser then + pcall(vim.treesitter.start, buf, ft) + end + end + end +}) +vim.api.nvim_create_autocmd("User", { + pattern = "TSUpdate", + callback = function() + vim.cmd([[TSEnable highlight]]) + end, +}) vim.api.nvim_create_autocmd({ "BufWritePost" }, { pattern = "*.templ", callback = function() @@ -146,6 +166,14 @@ vim.api.nvim_create_autocmd("FileType", { vim.opt_local.cindent = false end, }) + +vim.api.nvim_create_autocmd("VimResized", { + pattern = "*", + callback = function() + vim.opt.scrolloff = vim.fn.floor(vim.fn.winheight(0) / 2) + end, +}) + -- vim.api.nvim_create_autocmd("InsertEnter", { -- pattern = "*", -- command = "set norelativenumber", -- cgit v1.2.3