Skip to content

axieax/typo.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ™ˆ 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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages