From 20891ac03f37f13f144f7d97f584f169ec67be26 Mon Sep 17 00:00:00 2001 From: Georgi Dimitrov Date: Sun, 3 Mar 2024 11:17:06 +0000 Subject: [PATCH] neovim: simplify autocmd groups --- nvim/lua/plugins/ui.lua | 3 +-- nvim/lua/user/autocmd.lua | 23 +++++++---------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/nvim/lua/plugins/ui.lua b/nvim/lua/plugins/ui.lua index 8bc05aec..98588f20 100644 --- a/nvim/lua/plugins/ui.lua +++ b/nvim/lua/plugins/ui.lua @@ -199,9 +199,8 @@ return { config = function(_, opts) local toggleterm = require('toggleterm') - vim.api.nvim_create_augroup('user_toggleterm', { clear = true }) vim.api.nvim_create_autocmd('TermOpen', { - group = 'user_toggleterm', + group = vim.api.nvim_create_augroup('user_toggleterm', { clear = true }), desc = 'configure toggleterm keymaps', pattern = 'term://*', callback = function() diff --git a/nvim/lua/user/autocmd.lua b/nvim/lua/user/autocmd.lua index 118f1d95..72a9fb72 100644 --- a/nvim/lua/user/autocmd.lua +++ b/nvim/lua/user/autocmd.lua @@ -1,26 +1,18 @@ -- vim: foldmethod=marker -- Toggle highlighting current line only in active splits {{{1 -vim.api.nvim_create_augroup('user_toggle_cursorline', { clear = true }) -vim.api.nvim_create_autocmd({ 'VimEnter', 'WinEnter', 'BufWinEnter' }, { - group = 'user_toggle_cursorline', - desc = 'enable cursorline on focus', +vim.api.nvim_create_autocmd({ 'VimEnter', 'WinEnter', 'BufWinEnter', 'VimLeave', 'WinLeave', 'BufWinLeave' }, { + group = vim.api.nvim_create_augroup('user_toggle_cursorline', { clear = true }), + desc = 'toggle cursorline on focus', pattern = '*', - callback = function() - vim.opt_local.cursorline = true - end, -}) -vim.api.nvim_create_autocmd({ 'VimLeave', 'WinLeave', 'BufWinLeave' }, { - group = 'user_toggle_cursorline', - desc = 'disable cursorline on lost focus', - pattern = '*', - callback = function() - vim.opt_local.cursorline = false + callback = function(ev) + vim.opt_local.cursorline = ev.event:find('Enter') ~= nil end, }) -- Highlight yanked text {{{1 vim.api.nvim_create_autocmd({ 'TextYankPost' }, { + group = vim.api.nvim_create_augroup('user_highlight_yank', { clear = true }), desc = 'highlight yanked text', callback = function() vim.highlight.on_yank({ higroup = 'Visual', timeout = 500 }) @@ -28,9 +20,8 @@ vim.api.nvim_create_autocmd({ 'TextYankPost' }, { }) -- Set filetype to helm for YAML files in certain locations {{{1 -vim.api.nvim_create_augroup('user_filetype_helm', { clear = true }) vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufRead' }, { - group = 'user_filetype_helm', + group = vim.api.nvim_create_augroup('user_filetype_helm', { clear = true }), desc = 'set filetype to helm for YAML files in certain locations', pattern = { '*/templates/*.yaml', '*/templates/*.tpl' }, callback = function()