lua/core/autocmds.lua. Autocommands automatically execute actions in response to specific events.
LSP attachment guard
Prevents LSP from attaching to non-file buffers like fugitive, codediff, and other special buffer types.LspAttach event
LspAttach event
Event:
Source:
LspAttachSource:
lua/core/autocmds.lua:4Purpose: Detach LSP clients from buffers that use special URI schemes (except file://).Behavior:- Checks the buffer name when LSP attaches
- Allows
file://scheme and plain paths - Blocks all other URI schemes (like
fugitive://,codediff://, etc.) - Schedules client detachment for non-file buffers
This prevents unnecessary LSP diagnostics and completions in special buffers that aren’t actual files.
Comment formatting
Disables automatic comment continuation on new lines.BufEnter event
BufEnter event
Event:
Source:
BufEnterSource:
lua/core/autocmds.lua:20Purpose: Prevent Neovim from automatically continuing comments when pressing Enter.Behavior:- Removes
c,r, andoflags fromformatoptions c: Don’t auto-wrap comments using textwidthr: Don’t auto-insert comment leader after Enter in insert modeo: Don’t auto-insert comment leader after ‘o’ or ‘O’ in normal mode
set formatoptions-=croThis runs every time you enter a buffer, ensuring the setting persists even if plugins or ftplugins try to override it.
Restore cursor position
Returns to the last known cursor position when reopening a file.BufReadPost event
BufReadPost event
Event:
Source:
BufReadPostSource:
lua/core/autocmds.lua:24Purpose: Jump to the last position where you were editing when you open a file.Behavior:- Reads the
"mark (last exit position) from the buffer - Validates that the position is within the current file’s line count
- Sets cursor to that position using
pcallfor safety - Only triggers when opening existing files
The
pcall wrapper ensures that errors in setting cursor position don’t crash Neovim.ESLint daemon cleanup
Stops the eslint_d daemon when exiting Neovim to prevent orphaned processes.VimLeavePre event
VimLeavePre event
Event:
Source:
VimLeavePreSource:
lua/core/autocmds.lua:35Purpose: Clean up eslint_d daemon process before Neovim exits.Behavior:- Checks if
eslint_dis installed and executable - Runs
eslint_d stopcommand on Neovim exit - Prevents orphaned daemon processes from consuming system resources
Quick close for special filetypes
Allows closing certain buffer types with just theq key.
FileType event
FileType event
Event:
Group:
Source:
FileTypeGroup:
close_with_qSource:
lua/core/autocmds.lua:44Purpose: Map q to close special buffers like help, quickfix, and plugin windows.Affected filetypes:PlenaryTestPopup- Plenary test outputhelp- Vim help windowslspinfo- LSP information windowman- Manual pagesnotify- Notification windowsqf- Quickfix listspectre_panel- Search/replace panelstartuptime- Startup profilingtsplayground- Treesitter playgroundneotest-output- Test outputcheckhealth- Health check resultsneotest-summary- Test summaryneotest-output-panel- Test output panelcodediff- Code diff viewer
- Sets buffer to not listed (
buflisted = false) - Maps
qin normal mode to:closecommand - Mapping is buffer-local and silent
The autogroup is created with
clear = true to prevent duplicate autocommands if the config is reloaded.Summary
This configuration includes 5 autocommands that handle:- LSP attachment filtering - Keeps LSP focused on real files
- Comment formatting - Prevents annoying auto-comments
- Cursor position restoration - Picks up where you left off
- Daemon cleanup - Prevents orphaned eslint_d processes
- Quick window closing - Streamlines workflow with special buffers