1
0
mirror of https://github.com/dcarrillo/dotfiles.git synced 2024-11-15 06:51:12 +00:00
dotfiles/.config/nvim/lua/core/autocommands.lua

59 lines
1.5 KiB
Lua
Raw Normal View History

2022-10-01 11:46:18 +00:00
-- Highlight Yanked Text
vim.api.nvim_create_autocmd({ "TextYankPost" }, {
callback = function()
2023-01-20 17:57:58 +00:00
vim.highlight.on_yank({ higroup = "Visual", timeout = 250 })
2022-10-01 11:46:18 +00:00
end,
})
2022-10-02 15:38:01 +00:00
-- Set expandtab=true in several file types
2022-10-01 11:46:18 +00:00
vim.api.nvim_create_autocmd({ "FileType" }, {
2022-10-19 18:06:39 +00:00
pattern = { "go", "makefile", "lua" },
2022-10-01 11:46:18 +00:00
callback = function()
vim.opt_local.expandtab = false
end,
})
-- Use 'q' to quit from common plugins
vim.api.nvim_create_autocmd({ "FileType" }, {
2022-10-14 18:40:51 +00:00
pattern = { "qf", "help", "man", "lspinfo" },
2022-10-01 11:46:18 +00:00
callback = function()
vim.cmd([[
nnoremap <silent> <buffer> q :close<CR>
set nobuflisted
]])
end,
})
-- Ensure terraform files use hcl LSP
vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, {
pattern = { "*.tf" },
callback = function()
vim.cmd([[
set filetype=hcl
]])
end,
})
-- 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 turned off.")
end
end
end,
})