A Neovim plugin that automatically adds and maintains filename comments at the top of your files. With the growing popularity of LLMs and AI coding assistants, having clear file identifiers is increasingly important for context awareness.
- Automatic Comment Generation: Adds/updates filename comments on file save
- Smart Path Resolution: Uses Git root or relative paths intelligently
- Git Integration:
- Respects
.gitignorerules - Uses Git root for consistent path references
- Respects
- Language Aware:
- Supports multiple programming languages
- Uses appropriate comment syntax for each filetype
- Skips unsupported files (e.g., JSON)
- Zero Config: Works out of the box with sensible defaults
- Lightweight: Minimal impact on save operations
Using lazy.nvim
{
"ekhar/filename_cc.nvim",
event = "BufWritePre", -- Load right before saving
config = function()
require("filename_cc").setup()
end,
}Using packer.nvim
use {
'ekhar/filename_cc.nvim',
config = function()
require('filename_cc').setup()
end
}Using vim-plug
Plug 'ekhar/filename_cc.nvim'After installation, add to your init.lua:
require('filename_cc').setup()The plugin works out of the box, but can be customized:
require('filename_cc').setup({
-- Enable/disable the plugin
enabled = true,
-- Skip specific filetypes
skip_filetypes = { "json", "markdown" },
-- Custom comment format for specific filetypes
comment_formats = {
lua = "-- %s",
python = "# %s",
-- Add your own formats
},
-- Format of the filename comment
-- Available variables: {filepath}, {filename}, {git_root}
format = "filename: {filepath}",
-- Position of the comment (1 = top of file)
position = 1,
})The plugin works automatically after setup:
- Save any file to add/update the filename comment
- Comments are formatted based on filetype:
# filename: src/main.py// filename: src/index.js-- filename: lua/config/init.lua- Neovim >= 0.8.0
- Git (optional) - for git-root path resolution and
.gitignoresupport
-
Comments not appearing:
- Ensure the filetype is supported
- Check if the file is git-ignored
- Verify the plugin is loaded (
:PackerStatusor:Lazy)
-
Wrong comment syntax:
- Add custom comment format in setup configuration
- File an issue with the filetype details
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to your branch
- Open a Pull Request
Please ensure your PR includes:
- Clear description of changes
- Tests for new features
- Documentation updates
MIT License - See LICENSE for details
- Inspired by the need for better context in AI-assisted coding
- Thanks to all contributors and users for their feedback and support
- Open an issue for bugs or feature requests
- Star the repository if you find it useful
- Follow @ekhar for updates