A small Neovim extension to prevent AI coding plugins (e.g. copilot.lua)
from attaching to files and directories specified in an .aiignore file.
- Respects
.aiignorefiles in your project root and subdirectories. - Uses the same
.gitignoreformat and semantics with git. - Caches
.aiignorefiles for better performance.
You can install this plugin using your favorite package manager.
To use this extension, you need to require it and use its should_ignore
function in your AI extension setup.
See below for an example setup with copilot.lua:
{
-- Example with "zbirenbaum/copilot.lua"
"zbirenbaum/copilot.lua",
cmd = "Copilot",
event = "InsertEnter",
dependencies = { "ozars/aiignore.nvim" }, -- Ensure aiignore is loaded before copilot.lua
config = function()
require("copilot").setup({
-- Other copilot.lua settings
should_attach = function(bufnr)
local aiignore = require("aiignore")
return not aiignore.should_ignore(bufnr, {
-- File and directory names configurations.
aiignore_filename = ".aiignore", -- The name of the .aiignore file.
-- aiignore_filename = { ".aiexclude", ".aiignore" }, -- Multiple names are also supported. All of them will be checked.
git_dirname = ".git", -- The name of the directory which will be used for finding a repository root.
-- Logging and notifications configurations.
warn_ignored = false, -- Whether to notify the user if the file is ignored.
warn_not_ignored = false, -- Whether to notify the user if the file is not ignored.
debug_log = false, -- Whether to log debug messages.
quiet = false, -- Whether to ignore errors silently.
-- Buffer configurations.
should_ignore_invalid_buffers = true, -- Whether to ignore invalid buffers.
should_ignore_unnamed_buffers = true, -- Whether to ignore unnamed buffers.
})
end,
})
end,
}Create an .aiignore file in the root of your project (the same directory that
contains your .git folder). The format is identical to .gitignore. Similar to
.gitignore, you can have .aiignore files in subdirectories of the repository,
which will only affect those directories.
If a file is not in a git repository, the extension checks for any .aiignore
files in the same directory as the buffer path.
# Ignore secrets and environment files
.env
*.secret
credentials.json
/config/private.yml
# Ignore specific files
/src/legacy/do_not_touch.js
With the configuration above, (a configured) AI extension will not attach to or provide suggestions for any files or directories matching these patterns.