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 | 🔜 | 🔜 |
- Generate docstrings for functions
- Support for multiple docstring styles (Google, NumPy, Sphinx)
- Interactive template editor with live preview
- Custom template support
- Language-agnostic design (currently supporting Python, more languages coming soon)
- Easy-to-use commands and keymaps
- Customizable keybindings
neodoc.mp4
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 template
Position your cursor inside a function and use one of the following:
- Use the
:NeoDoc generate
command - Press
<leader>dd
(default keymap) - Use
: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 preview
The template editor provides a split window interface with:
- Left pane: Template editor for modifying the template
- Right pane: Live preview showing how the template will look
Features:
- Live preview updates as you type
- Proper indentation handling
- Automatic template loading on startup
- Template persistence across sessions
Custom templates support the following placeholders:
{params}
- Function parameters{return_type}
- Return type annotation
Templates 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
"""
- Support for additional programming languages
- Class docstring generation
- AI-powered docstring generation
- Enhanced template customization options
- Language-specific template features
- Improved parameter type detection
- Integration with language servers