Did you mean to open this file instead?
โจ Typo.nvim is a plugin which addresses common typos when opening files in Neovim, suggesting files you probably meant to load instead. This plugin can be configured to detect the following typos:
ย ย ๐ Accidentally creating a new file
- Enabled by default
- Non-existent file
foo
was opened, butfoo.bar
exists.package
opened instead ofpackage.json
orpackage-lock.json
index
opened instead ofindex.js
orindex.test.js
ย ย ๐ Accidentally opening a directory instead of a file
- Enabled by default
- Directory
foo
was opened, butfoo.lua
exists.- Lua module
plugin
directory opened instead ofplugin.lua
file .git
directory opened instead of.github
directory
- Lua module
ย ย ๐ Check additional files
- Disabled by default
- Existent file
foo.bar
opened, butfoo.bar.baz
also exists.help.ts
opened instead ofhelp.tsx
app.log
opened instead of its backupapp.log.20221023
... and more to come! This plugin can be easily extensible to detect additional typos due to its design.
typo.demo.mp4
Install this plugin with your package manager of choice.
use("axieax/typo.nvim")
"axieax/typo.nvim"
This plugin works out of the box, so no configuration is required unless you want to adjust certain options with require("typo").setup()
. Here are the default options users can customize by passing a new table overriding desired fields, to the setup
function:
{
-- open the selected correct file in the current buffer
replace_buffer = true,
-- file patterns which shouldn't be suggested (e.g. "package-lock.json")
ignored_suggestions = { "*.swp" },
-- display logs with this severity or higher
log_level = vim.log.levels.INFO,
autocmd = {
enabled = true,
pattern = "*",
ignored_filetypes = {},
auto_select = false,
check_new_file = true, -- non-existent file `foo` opened but `foo.bar` exists
check_directory = true, -- dir `foo` opened but `foo.lua` exists
check_additional_files = false, -- file `foo` exists, but file `foo.bar` also exists
},
},
You can customize the appearance of vim.ui.select
for displaying the suggested files with plugins such as dressing.nvim. The demo above uses the Telescope picker from dressing.nvim, which allows me to easily filter and fuzzy search through the suggested files.
This plugin exposes a public API for manually run a typo check on the current buffer. You can create a Neovim command for this with:
vim.api.nvim_create_user_command("Typo", function()
require("typo").check()
end)
Alternatively, you can also set a keymap for this with:
vim.keymap.set("n", "\\<Tab>", function()
require("typo").check()
end, { desc = "Typo check" })
More features are continually being added to this plugin (see ๐บ๏ธ Roadmap). Feel free to file an issue or create a PR for any features / fixes :)
It is recommended to subscribe to the ๐ Breaking Changes thread to be updated on potentially breaking changes to this plugin, as well as resolution strategies.