A Neovim plugin for generating docstrings across multiple programming languages. Currently focused on Python with plans to expand support for more languages.
Language | Function Docstring | Class Docstring |
---|---|---|
Python | ✅ | ❌ |
JavaScript | 🔜 | 🔜 |
TypeScript | 🔜 | 🔜 |
Go | 🔜 | 🔜 |
Rust | 🔜 | 🔜 |
https://github.com/user-attachments/assets/9126d21e-14ce-4292-abca-1c2ab9b15e81
Using packer.nvim:
use {
'sunnytamang/neodoc.nvim',
config = function()
require('neodoc').setup({
-- your configuration here
})
end
}
Using lazy.nvim:
{
'sunnytamang/neodoc.nvim',
config = function()
require('neodoc').setup({
-- your configuration here
})
end
}
Configure NeoDoc using the setup function in your Neovim configuration file (init.lua):
require('neodoc').setup({
-- Python interpreter path (default: 'python3')
python_interpreter = 'python3',
-- Default docstring style (default: 'google')
docstring_style = 'google',
-- Enable keymaps (default: true)
enable_keymaps = true,
-- Keymap prefix (default: '<leader>d')
keymap = '<leader>d',
-- Use custom template (default: false)
use_custom_template = false
})
NeoDoc provides flexible keymapping options through the configuration:
Enable/Disable Keymaps
require('neodoc').setup({
enable_keymaps = false -- Disable all keymaps
})
Custom Keymap Prefix
require('neodoc').setup({
keymap = '<leader>g' -- Change prefix to <leader>g
})
When keymaps are enabled, the following mappings are created using your specified prefix:
Mode | Keymap | Action |
---|---|---|
Normal | <prefix>d |
Generate docstring |
Normal | <prefix>c |
Change docstring style |
Normal | <prefix>e |
Open template editor |
Normal | <prefix>s |
Save template (in editor) |
Normal | <C-q> |
Close template editor |
For example, if you set keymap = '<leader>g'
, you would get:
<leader>gd
- Generate docstring<leader>gc
- Change style<leader>ge
- Open editor<leader>gs
- Save templatePosition your cursor inside a function and use one of the following:
:NeoDoc generate
command<leader>dd
(default keymap):NeoDoc template
to open the template editor:NeoDoc generate
- Generate docstring at cursor:NeoDoc config
- Show current configuration:NeoDoc set_style <style>
- Set docstring style (google, numpy, sphinx):NeoDoc set_python <path>
- Set Python interpreter path:NeoDoc template
- Open template editor:NeoDoc preview
- Show docstring previewThe template editor provides a split window interface with:
Features:
Custom templates support the following placeholders:
{params}
- Function parameters{return_type}
- Return type annotationTemplates are saved at: ~/.config/nvim/lua/neodoc/custom_template.lua
Example template:
"""
TODO: Add function description
Parameters:
----------
{params}
Returns:
-------
{return_type}
Raises:
------
TODO: Add exceptions that might be raised
Examples:
--------
>>> TODO: Add example usage
"""