1
0
mirror of https://github.com/dcarrillo/dotfiles.git synced 2025-02-22 16:47:58 +00:00
dotfiles/.config/nvim/lua/core/autocommands.lua

84 lines
2.0 KiB
Lua
Raw Normal View History

2022-10-01 13:46:18 +02:00
-- Highlight Yanked Text
2025-02-02 19:28:41 +01:00
vim.api.nvim_create_autocmd("TextYankPost", {
2022-10-01 13:46:18 +02:00
callback = function()
2025-02-02 19:28:41 +01:00
(vim.hl or vim.highlight).on_yank()
2022-10-01 13:46:18 +02:00
end,
})
-- resize splits if window got resized
vim.api.nvim_create_autocmd({ "VimResized" }, {
callback = function()
local current_tab = vim.fn.tabpagenr()
vim.cmd("tabdo wincmd =")
vim.cmd("tabnext " .. current_tab)
end,
})
2022-10-02 17:38:01 +02:00
-- Set expandtab=true in several file types
2022-10-01 13:46:18 +02:00
vim.api.nvim_create_autocmd({ "FileType" }, {
2022-10-19 20:06:39 +02:00
pattern = { "go", "makefile", "lua" },
2022-10-01 13:46:18 +02:00
callback = function()
vim.opt_local.expandtab = false
end,
})
-- Use 'q' to quit from common plugins
vim.api.nvim_create_autocmd({ "FileType" }, {
pattern = {
"help",
"lspinfo",
"man",
"notify",
"qf",
"query",
"checkhealth",
},
callback = function(event)
vim.bo[event.buf].buflisted = false
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = event.buf, silent = true })
2022-10-01 13:46:18 +02:00
end,
})
-- Ensure terraform files use hcl LSP
vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, {
pattern = { "*.tf" },
callback = function()
vim.cmd([[
set filetype=hcl
]])
end,
})
2024-09-26 20:21:33 +02:00
vim.api.nvim_create_autocmd("FileType", {
pattern = "hcl",
command = "setlocal shiftwidth=2 tabstop=2",
})
2025-01-26 13:30:36 +01:00
-- helm files indentation
vim.api.nvim_create_autocmd("FileType", {
pattern = "helm",
command = "setlocal shiftwidth=2 tabstop=2",
})
-- Disable some plugins on very large files
vim.api.nvim_create_autocmd({ "BufEnter" }, {
pattern = { "*" },
callback = function(args)
local highlighter = require("vim.treesitter.highlighter")
local ts_was_active = highlighter.active[args.buf]
local file_size = vim.fn.getfsize(args.file)
if file_size > 1024 * 1024 then
vim.cmd("TSBufDisable highlight")
vim.cmd("syntax off")
vim.cmd("syntax clear")
vim.cmd("IlluminatePauseBuf")
vim.cmd("NoMatchParen")
vim.cmd("UfoDisable")
vim.cmd("IBLDisable")
vim.cmd("LspStop")
if ts_was_active then
vim.notify("File larger than 1MB; syntax highlighting and heavy CPU use plugins are turned off.")
end
end
end,
})