default-new-file.nvim is a Neovim plugin that automatically inserts a predefined template into newly created files based on their file type. It also provides commands for managing and editing templates.
- Automatically apply templates to new files based on their file type.
- Skip template application if the file already exists.
- Manage templates with a built-in command for editing them.
- Customizable patterns for file matching and template locations.
Using Lazy.nvim
{
'goropikari/default-new-file.nvim',
opts = {
-- default config
pattern = { '*' }, -- Match all file types by default
template_path = vim.fn.stdpath('data') .. '/default-new-file.nvim', -- Default template storage
},
}
To initialize the plugin, call the setup
function:
require('default-new-file').setup({
pattern = { '*.md', '*.lua' }, -- Specify patterns for files
template_path = vim.fn.stdpath('data') .. '/custom-template-path',
})
When you create a new file (e.g., :e new_file.lua
), the plugin will:
- Check the file type of the new file.
- Look for a corresponding template in the specified
template_path
. - If a matching template exists, its content will be inserted into the new file.
Use the :DefaultNewFile
command to create or edit templates for specific file types.
:DefaultNewFile lua
- This opens the template file for
lua
file types. - If the template file does not exist, a new one will be created at the configured
template_path
.
This plugin is distributed under the MIT License.