axieax / typo.nvim

πŸ™ˆ Suggest files for typos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ™ˆ typo.nvim

Did you mean to open this file instead?

Neovim Version Repo Stars Repo Size

✨ 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, but foo.bar exists.
    • package opened instead of package.json or package-lock.json
    • index opened instead of index.js or index.test.js

   πŸ“ Accidentally opening a directory instead of a file

  • Enabled by default
  • Directory foo was opened, but foo.lua exists.
    • Lua module plugin directory opened instead of plugin.lua file
    • .git directory opened instead of .github directory

   πŸ”Ž Check additional files

  • Disabled by default
  • Existent file foo.bar opened, but foo.bar.baz also exists.
    • help.ts opened instead of help.tsx
    • app.log opened instead of its backup app.log.20221023

... and more to come! This plugin can be easily extensible to detect additional typos due to its design.

typo.demo.mp4

πŸ“¦ Installation

Install this plugin with your package manager of choice.

use("axieax/typo.nvim")
"axieax/typo.nvim"

βš™οΈ Configuration

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
  },
},

🎨 UI Customization

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.

πŸ—ΊοΈ Mappings

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" })

🚧 Stay Updated

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.

About

πŸ™ˆ Suggest files for typos

License:MIT License


Languages

Language:Lua 98.8%Language:Makefile 0.7%Language:Vim Script 0.5%