[!WARNING] This plugin was renamed from
telescope-import.nvimtoimport.nvimas it now supports multiple pickers. Old GitHub URLs will still redirect, but please update your plugin spec to use:{ "piersolenski/import.nvim" }The previous setup method of registering the plugin as a Telescope extension is still supported, but the new method is recommended for access to latest features.
Often we find ourselves importing the same modules over and over again in an existing project. import.nvim helps you add import statements faster by searching your project for existing imports and presenting them in a picker. Instead of typing out imports from scratch or yanking them from other files, you get a searchable list of all imports already used in your project, sorted by frequency of use.
Think of it as "import autocomplete" based on your project's actual usage patterns. It's particularly useful when:
https://github.com/user-attachments/assets/b5c2d7bd-ced7-44d1-abd2-d96de37a05e8
<script> tags)Install ripgrep.
-- Lazy
{
'piersolenski/import.nvim',
dependencies = {
-- One of the following pickers is required:
'nvim-telescope/telescope.nvim',
-- 'folke/snacks.nvim',
-- 'ibhagwan/fzf-lua',
},
opts = {
picker = "telescope",
},
keys = {
{
"<leader>i",
function()
require("import").pick()
end,
desc = "Import",
},
},
}
import.nvim requires no configuration out of the box, but you can tweak it in the following ways:
{
-- The picker to use
picker = "telescope" | "snacks" | "fzf-lua",
-- Imports can be added at a specified line whilst keeping the cursor in place
insert_at_top = true,
-- Optionally support additional languages or modify existing languages...
custom_languages = {}
}
The custom_languages configuration allows you to add support for new languages or customize existing ones.
To add a new language: All fields are required
extensions: File extensions that ripgrep will search (use rg --type-list to see supported types)filetypes: Neovim filetypes where this configuration applies regex: Regular expression pattern to match import statements in the languageinsert_at_line (optional): Line number where imports should be inserted (defaults to 1)To customize an existing language: Only specify the fields you want to override
filetypes: Must match the existing language's filetypes exactlyAdd support for a new language:
custom_languages = {
{
extensions = { "elm" },
filetypes = { "elm" },
regex = [[^import\s+([\w.]+)(?:\s+as\s+\w+)?(?:\s+exposing\s+.+)?]],
}
}
Override just the insertion behavior for Vue.js:
custom_languages = {
{
filetypes = { "vue" },
insert_at_line = function()
-- Insert before closing <script> tag instead of after the opening tag
return vim.fn.search("</script>", "n") + 1
end,
}
}
Override multiple aspects of an existing language:
custom_languages = {
{
filetypes = { "vue" },
regex = [[^import\s+.*from\s+['\"](.+)['\"];?]], -- Custom regex
insert_at_line = 2, -- Fixed line number
}
}
Custom languages are merged with built-in language support, with your configurations taking precedence over defaults.
If you created a custom language configuration that works well, please consider contributing it to make it a default supported language! Here's how:
feature/add-<language>-support (e.g., feature/add-elm-support)lua/import/language/regex.lualua/import/language/languages.luatests/import/core/regex_spec.luamake check to ensure everything worksYour contribution will help other users of the same language!
:Import
require("import").pick()
As well as a passionate Vim enthusiast, I am a Full Stack Developer and Technical Lead from London, UK.
Whether it's to discuss a project, talk shop or just say hi, I'd love to hear from you!