Neovim-Specific Lua Doc Conventions
Neovim-specific annotation extensions and conventions beyond standard LuaCATS.
Neovim-Only Annotations
@nodoc — Suppress Documentation
Tells Neovim's doc generator to skip this item.
--- @nodoc
--- @class vim.NIL
vim.NIL = ...
--- @nodoc
vim.log = { ... }
@note — Important Callouts
---@note {fn} will be removed on error.
---@note {fn} won't be invoked recursively.
@brief — Module-Level Description
--- @brief A "treesitter node" represents one specific element of the parsed contents of a buffer...
@since — Version Marker
--- @since 0
function vim.ui_attach(ns, opts, callback) end
@inlinedoc — Inline Doc Blocks
Internal Neovim mechanism for inline documentation blocks.
--- @inlinedoc
The _meta/ Directory Convention
Files in vim/_meta/ directories are never loaded at runtime — they exist
purely for LuaLS type checking.
Meta File Structure
--- @meta _
-- THIS FILE IS GENERATED
-- DO NOT EDIT
error('Cannot require a meta file')
--- @class vim.api.keyset.win_config
--- @field external? boolean
--- @field focusable? boolean
--- @field height? integer
Naming
- Directory:
_meta/ or _meta/
- File:
api.lua, api_keysets.lua, builtin.lua, etc.
- Submodules:
vim/treesitter/_meta/tsnode.lua
Keyset Naming Convention
Option/parameter table types follow vim.api.keyset.*:
--- @class vim.api.keyset.create_autocmd
--- @class vim.api.keyset.win_config
--- @class vim.api.keyset.user_command
--- @class vim.api.keyset.keymap
--- @class vim.api.keyset.highlight
Plugin convention: MyPlugin.Opts, MyPlugin.State.
Plugin Documentation Patterns
Config/Opts with Callbacks
--- @class MyPlugin.Opts
--- @field enabled? boolean Whether the plugin is active
--- @field timeout? integer Timeout in ms (default: 1000)
--- @field on_done? fun(result: string) Callback when operation completes
--- @field filter? string[] File patterns to include
--- @param opts? MyPlugin.Opts
--- @return boolean success
function M.setup(opts)
Module Export with State
--- @class MyPlugin.State
--- @field bufnr? integer
--- @field items string[]
--- @type MyPlugin.State
local state = { items = {} }
--- Get current items.
--- @return string[]
function M.get_items()
return state.items
end
return M
Folke/lazy.nvim Inline Style
Compact inline ---@type annotations on table assignments:
---@class LazyConfig
M.defaults = {
---@type LazySpec
spec = nil,
---@type string | fun(plugin: LazyPlugin): string
path = "~/projects",
---@type string[] list of plugins to disable
disabled_plugins = {},
---@type number? max concurrent tasks
concurrency = nil,
}
Meta Type-Only Files
For shipping types without runtime code:
--- @meta _
error('Cannot require a meta file')
--- @class MyPlugin.Types.Result
--- @field path string
--- @field score number
--- @alias MyPlugin.Types.Filter fun(item: string): boolean
return nil -- never reached
Keymap Documentation
Always use desc on keymaps:
vim.keymap.set('n', '<leader>f', function()
require('telescope.builtin').find_files()
end, {
desc = 'Find files',
noremap = true,
silent = true,
})
Typed via vim.api.keyset.keymap:
--- @class vim.api.keyset.keymap
--- @field noremap? boolean
--- @field silent? boolean
--- @field expr? boolean
--- @field callback? function
--- @field desc? string
Autocmd Documentation
Callback Args
--- @class vim.api.keyset.create_autocmd.callback_args
--- @field id integer autocommand id
--- @field event string name of the triggered event
--- @field match string expanded <amatch>
--- @field buf integer expanded <abuf>
--- @field data? any arbitrary data
vim.api.nvim_create_autocmd('BufWritePost', {
group = my_augroup,
pattern = '*.lua',
callback = function(ev)
print('Buffer ' .. ev.buf .. ' was saved')
end,
desc = 'Lint Lua files on save',
})
Typed Autocmd Creation
--- @param opts vim.api.keyset.create_autocmd
--- @return integer augroup
vim.api.nvim_create_autocmd = function(opts) end
Diagnostic Suppression Patterns
Neovim uses @diagnostic heavily to suppress false positives in dynamic code:
--- @diagnostic disable: undefined-doc-name,luadoc-miss-symbol
--- @diagnostic disable-next-line: unused-function, unused-local
--- @diagnostic disable-next-line: undefined-doc-param
--- @diagnostic disable-next-line: inject-field
--- @diagnostic disable-next-line: redundant-return-value
--- @diagnostic disable-next-line: no-unknown
--- @diagnostic disable-next-line: unused-local
Common in generated files and metatable-based dynamic code where LuaLS cannot
infer types.
Markdown source
File outline
# Neovim-Specific Lua Doc Conventions
Neovim-specific annotation extensions and conventions beyond standard LuaCATS.
## Neovim-Only Annotations
### @nodoc — Suppress Documentation
Tells Neovim's doc generator to skip this item.
```lua
--- @nodoc
--- @class vim.NIL
vim.NIL = ...
--- @nodoc
vim.log = { ... }
```
### @note — Important Callouts
```lua
---@note {fn} will be removed on error.
---@note {fn} won't be invoked recursively.
```
### @brief — Module-Level Description
```lua
--- @brief A "treesitter node" represents one specific element of the parsed contents of a buffer...
```
### @since — Version Marker
```lua
--- @since 0
function vim.ui_attach(ns, opts, callback) end
```
### @inlinedoc — Inline Doc Blocks
Internal Neovim mechanism for inline documentation blocks.
```lua
--- @inlinedoc
```
---
## The `_meta/` Directory Convention
Files in `vim/_meta/` directories are **never loaded at runtime** — they exist
purely for LuaLS type checking.
### Meta File Structure
```lua
--- @meta _
-- THIS FILE IS GENERATED
-- DO NOT EDIT
error('Cannot require a meta file')
--- @class vim.api.keyset.win_config
--- @field external? boolean
--- @field focusable? boolean
--- @field height? integer
```
### Naming
- Directory: `_meta/` or `_meta/`
- File: `api.lua`, `api_keysets.lua`, `builtin.lua`, etc.
- Submodules: `vim/treesitter/_meta/tsnode.lua`
### Keyset Naming Convention
Option/parameter table types follow `vim.api.keyset.*`:
```lua
--- @class vim.api.keyset.create_autocmd
--- @class vim.api.keyset.win_config
--- @class vim.api.keyset.user_command
--- @class vim.api.keyset.keymap
--- @class vim.api.keyset.highlight
```
Plugin convention: `MyPlugin.Opts`, `MyPlugin.State`.
---
## Plugin Documentation Patterns
### Config/Opts with Callbacks
```lua
--- @class MyPlugin.Opts
--- @field enabled? boolean Whether the plugin is active
--- @field timeout? integer Timeout in ms (default: 1000)
--- @field on_done? fun(result: string) Callback when operation completes
--- @field filter? string[] File patterns to include
--- @param opts? MyPlugin.Opts
--- @return boolean success
function M.setup(opts)
```
### Module Export with State
```lua
--- @class MyPlugin.State
--- @field bufnr? integer
--- @field items string[]
--- @type MyPlugin.State
local state = { items = {} }
--- Get current items.
--- @return string[]
function M.get_items()
return state.items
end
return M
```
### Folke/lazy.nvim Inline Style
Compact inline `---@type` annotations on table assignments:
```lua
---@class LazyConfig
M.defaults = {
---@type LazySpec
spec = nil,
---@type string | fun(plugin: LazyPlugin): string
path = "~/projects",
---@type string[] list of plugins to disable
disabled_plugins = {},
---@type number? max concurrent tasks
concurrency = nil,
}
```
### Meta Type-Only Files
For shipping types without runtime code:
```lua
--- @meta _
error('Cannot require a meta file')
--- @class MyPlugin.Types.Result
--- @field path string
--- @field score number
--- @alias MyPlugin.Types.Filter fun(item: string): boolean
return nil -- never reached
```
---
## Keymap Documentation
Always use `desc` on keymaps:
```lua
vim.keymap.set('n', '<leader>f', function()
require('telescope.builtin').find_files()
end, {
desc = 'Find files',
noremap = true,
silent = true,
})
```
Typed via `vim.api.keyset.keymap`:
```lua
--- @class vim.api.keyset.keymap
--- @field noremap? boolean
--- @field silent? boolean
--- @field expr? boolean
--- @field callback? function
--- @field desc? string
```
---
## Autocmd Documentation
### Callback Args
```lua
--- @class vim.api.keyset.create_autocmd.callback_args
--- @field id integer autocommand id
--- @field event string name of the triggered event
--- @field match string expanded <amatch>
--- @field buf integer expanded <abuf>
--- @field data? any arbitrary data
vim.api.nvim_create_autocmd('BufWritePost', {
group = my_augroup,
pattern = '*.lua',
callback = function(ev)
print('Buffer ' .. ev.buf .. ' was saved')
end,
desc = 'Lint Lua files on save',
})
```
### Typed Autocmd Creation
```lua
--- @param opts vim.api.keyset.create_autocmd
--- @return integer augroup
vim.api.nvim_create_autocmd = function(opts) end
```
---
## Diagnostic Suppression Patterns
Neovim uses `@diagnostic` heavily to suppress false positives in dynamic code:
```lua
--- @diagnostic disable: undefined-doc-name,luadoc-miss-symbol
--- @diagnostic disable-next-line: unused-function, unused-local
--- @diagnostic disable-next-line: undefined-doc-param
--- @diagnostic disable-next-line: inject-field
--- @diagnostic disable-next-line: redundant-return-value
--- @diagnostic disable-next-line: no-unknown
--- @diagnostic disable-next-line: unused-local
```
Common in generated files and metatable-based dynamic code where LuaLS cannot
infer types.