-- Autocommands migrated from the original init.vim. -- Plugin-specific autocommands (LSP, windownav, etc.) stay in their modules. local api = vim.api local init_group = api.nvim_create_augroup('InitVim', { clear = true }) -- Turn search highlighting off when leaving Insert mode; mappings for n/N -- in 01-mappings.lua re-enable highlighting when navigating results. api.nvim_create_autocmd('InsertLeave', { group = init_group, callback = function() vim.opt.hlsearch = false end, desc = 'Clear search highlighting after insert mode', }) -- Highlight matches whenever entering the / or ? search command line. api.nvim_create_autocmd('CmdlineEnter', { group = init_group, pattern = { '/', '?' }, callback = function() vim.opt.hlsearch = true end, desc = 'Enable search highlighting on search', }) vim.api.nvim_create_autocmd('TextYankPost', { group = vim.api.nvim_create_augroup('HighlightYank', { clear = true }), callback = function() vim.hl.hl_op({ higroup = 'IncSearch', timeout = 100 }) end, }) vim.api.nvim_create_autocmd('TextPutPost', { group = vim.api.nvim_create_augroup('HighlightPut', { clear = true }), callback = function() vim.hl.hl_op({ higroup = 'IncSearch', timeout = 100 }) end, }) api.nvim_create_autocmd({ 'FocusGained', 'BufEnter' }, { group = init_group, command = 'checktime', desc = 'Check for changes to files on disk', }) -- The original UseTerminal group only opened a terminal if the entered buffer -- *itself* was named after a directory. Guard that explicitly: the new -- open_terminal_on_directory() helper defaults to the file's parent directory, -- which would otherwise open a terminal whenever you entered any file. local terminal_group = api.nvim_create_augroup('UseTerminal', { clear = true }) api.nvim_create_autocmd({ 'BufNewFile', 'BufEnter' }, { group = terminal_group, callback = function(args) local dirname = api.nvim_buf_get_name(args.buf) if dirname ~= '' and vim.fn.isdirectory(dirname) == 1 then -- Defined by 03-commands.lua. Resolve at callback time so our -- numbered config loader may source this file independently. if type(_G.open_terminal_on_directory) == 'function' then _G.open_terminal_on_directory(dirname) end end end, desc = 'Open a terminal when editing a directory buffer', })