
fold-imports.nvim
github.com/dmtrkovalenko/fold-imports.nvim- Category
- Developer Tools
- Rank
- No. 1667Tools index
- Pricing
- Open Source
- Type
- TOOL
- Builder
- dmtrkovalenko
- GitHub
- 51 stars
- Latest release
- 1.0.0
- Date
About
Neovim plugin that automatically folds imports in any language using Treesitter — clear out the noise at the top of every file.
What it does
It reads each buffer’s syntax tree, matches configured dependency declarations, joins neighboring matches across blank lines, and creates manual folds with optional summary text. Automatic and manual operation are both available.
Why it's ranked here
A focused idea gets unusually broad language coverage and practical controls. Syntax-aware matching is more precise than line patterns, while comment handling, LSP-triggered refolding, debugging support, and cross-platform continuous integration make this credible for daily use. Parser-dependent tests can become pending, which weakens their assurance.
What's good
Language definitions are configurable rather than fixed. Built-in queries cover comments, Rust attributes, exports, includes, module declarations, and several other dependency forms. The implementation tracks its own fold ranges so removing them can preserve unrelated manual folds. Users can disable individual languages or add queries.
Tradeoffs
Every supported language needs its Tree-sitter parser, and custom languages require language-specific query knowledge. The default scope sometimes exceeds imports, including C preprocessor definitions and Rust module items. Individual declarations longer than the configured limit are excluded. Some folding tests skip meaningful assertions when parsers are unavailable.
How to use it well
Use it when large dependency sections interrupt code reading, especially across a multilingual Neovim setup. Keep automatic folding for routine navigation, or switch to manual control when imports carry context you often inspect. It changes presentation only. It does not sort, remove, or otherwise manage dependencies.
Technical notes+
The main implementation is in lua/fold_imports.lua, with defaults for ten language groups, Tree-sitter query selection, range filtering, fold tracking, and LSP edit proximity checks. plugin/fold_imports.lua performs automatic setup. tests/fold_imports_spec.lua uses Plenary Busted and parser-aware cases, while tests/minimal_init.lua provisions the test runtime. Makefile runs the suite headlessly. .github/workflows/lint-test.yml checks StyLua and tests stable and nightly Neovim on Ubuntu, macOS, and Windows. README.md and doc/fold-imports.nvim.txt document configuration, commands, and the Lua API.
Observed
- License
- MIT License
- Primary language
- Lua
- Runtime requirements
- Neovim 0.8.0 or newer, built-in Tree-sitter support, and language-specific parsers
- Install surface
- Documented configurations for lazy.nvim and packer.nvim; tagged releases are uploaded through LuaRocks automation
- Interfaces
- Three Neovim user commands plus a Lua API for folding, enabling, disabling, and toggling
- Built-in language groups
- TypeScript, JavaScript, Rust, C, C++, OCaml, Zig, Python, Go, and Dart
- Platform validation
- Continuous integration tests stable and nightly Neovim on Ubuntu, macOS, and Windows
- Test structure
- A Plenary Busted specification and headless Neovim test initializer are present
Read from README.md, Makefile, LICENSE, .stylua.toml, lua/fold_imports.lua, tests/minimal_init.lua, plugin/fold_imports.lua, doc/fold-imports.nvim.txt, tests/fold_imports_spec.lua, .github/workflows/docs.yml, .github/workflows/release.yml, .github/workflows/lint-test.yml, .github/ISSUE_TEMPLATE/bug_report.yml, .github/ISSUE_TEMPLATE/feature_request.yml.
What it can do
Automatically fold import statements
Source code file with import/include statements → Folded import sections in the editor
Detect import statements using Treesitter
Source code in any programming language → Identified import/include blocks
Hide import noise from file top
Source code file with imports at the beginning → Clean view with imports collapsed
Apply folding across multiple languages
Source files in different programming languages → Consistently folded imports regardless of language
Tags
Tech Stack
Comments (0)
No comments yet
Editorially curated, with community endorsements as a secondary signal. Corrections welcome.