Skip to content

Commit

Permalink
neovim: simplify autocmd groups
Browse files Browse the repository at this point in the history
  • Loading branch information
geodimm committed Mar 3, 2024
1 parent a59c41a commit 20891ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
3 changes: 1 addition & 2 deletions nvim/lua/plugins/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
23 changes: 7 additions & 16 deletions nvim/lua/user/autocmd.lua
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
-- 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 })
end,
})

-- 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()
Expand Down

0 comments on commit 20891ac

Please sign in to comment.