Run code when matching files are written.

Section: Lua autocommands

Create an autocmd

lua
lua
vim.api.nvim_create_autocmd("BufWritePost", {
  pattern = "*.lua",
  callback = function()
    print("saved lua file")
  end,
})
Explanation

Neovim’s Lua API makes event handling cleaner than old Vimscript groups.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Lua autocommands
Create an augroup
Group related autocmds together.
OpenIn sheetluasame section
Format on save with LSP
Trigger LSP formatting before write.
OpenIn sheetluasame section
Enable line numbers
Turn on absolute and relative line numbers.
OpenIn sheetlua2 tag match
Map a save command
Bind a normal-mode key to save the file.
OpenIn sheetlua2 tag match
Configure tabs and indentation
Set width and spacing rules.
OpenIn sheetlua2 tag match
Map Telescope file search
Bind a key to file-finding with a Lua callback.
OpenIn sheetlua2 tag match