A Neovim plugin that reads project-local .filetypemap files to define custom filetype mappings for file extensions.
Some projects use custom file extensions that Neovim doesn't recognize. For example, systemd quadlet files use .container, .network, .timer extensions. Instead of configuring these globally, you can drop a .filetypemap file in your project root.
{
'eingin/filetypemap.nvim',
event = 'VimEnter',
opts = {},
}use {
'eingin/filetypemap.nvim',
config = function()
require('filetypemap').setup()
end
}require('filetypemap').setup({
-- Show notification when mappings are loaded (default: true)
notify = true,
})Create a .filetypemap file in your project root:
# Systemd quadlet files
container=systemd
network=systemd
timer=systemd
# Custom formats
myext=json- One mapping per line:
extension=filetype - Lines starting with
#are comments - Empty lines are ignored
- Whitespace around
=is trimmed
| Command | Description |
|---|---|
:FiletypeMapReload |
Reload .filetypemap from current directory |
On setup, the plugin:
- Checks if
.filetypemapexists invim.fn.getcwd() - Parses extension mappings from the file
- Sets filetypes for matching buffers via autocmds
When you change directories (DirChanged event), the plugin automatically:
- Loads the new directory's
.filetypemap(if present) - Resets any open buffers that were affected by old mappings back to Neovim's default detection
- Applies new mappings to relevant open buffers
This ensures mappings are scoped to the current directory - switching projects won't leave stale mappings behind.
Tests use mini.test from mini.nvim.
# Run all tests (downloads mini.nvim on first run)
make test
# Run a specific test file
FILE=tests/test_filetypemap.lua make test_file
# Clean dependencies
make cleanMIT