nvim-tree
A Professional File Explorer for Neovim
nvim-tree is an essential file explorer plugin for Neovim, providing developers with an intuitive way to navigate and manage project files. Lightweight, highly configurable, and tightly integrated with Neovim’s ecosystem, it’s a must-have for any efficient workflow.
Key Features
-
Lightweight and Fast
Designed for performance, nvim-tree ensures seamless navigation, even with large codebases.
-
Git Integration
View the status of files and folders directly within the file tree. Git indicators make it easy to identify changes and staged files.
-
Intuitive Navigation
The tree structure allows quick access to files and directories. Key mappings streamline operations like creating, renaming, or deleting files.
-
Customizable Configuration
Fully configurable through Lua, nvim-tree adapts to your workflow, offering features like auto-resizing, filtering, and custom key bindings.
Installation with Lazy.nvim
To install nvim-tree with Lazy.nvim, add the following configuration to your Lazy setup:
{
"nvim-tree/nvim-tree.lua",
dependencies = {
"nvim-tree/nvim-web-devicons", -- optional, for file icons
},
config = function()
require("nvim-tree").setup()
end,
}
After installation, you can open the file tree with:
:NvimTreeToggle
Basic Configuration
Here’s an example of a basic setup to get you started:
require("nvim-tree").setup {
view = {
width = 30,
side = "left",
auto_resize = true,
},
renderer = {
group_empty = true,
},
git = {
enable = true,
ignore = false,
},
filters = {
dotfiles = true,
},
}
Key Features of the Configuration:
- View Settings: Adjusts the width and position of the tree.
- Renderer Options: Groups empty folders for a cleaner view.
- Git Integration: Displays Git status while respecting ignored files.
- Filters: Hides dotfiles for a more focused workspace.
Commands and Workflow
Here are the most commonly used commands to boost your productivity:
Command | Description |
---|---|
:NvimTreeToggle |
Opens or closes the file tree. |
:NvimTreeFindFile |
Locates the current file in the tree. |
a |
Creates a new file or directory. |
r |
Renames a file or directory. |
d |
Deletes a file or directory. |
q |
Closes the file tree. |
Visualizing the File Structure
Below is a simple visualization of how nvim-tree organizes your project:
graph TD A[Project Root] --> B[Folder 1] A --> C[Folder 2] B --> D[File 1.1] B --> E[File 1.2] C --> F[File 2.1] C --> G[File 2.2]
Advanced Customization
- Autocommands
Set up autocommands to automatically close nvim-tree when it’s the last open buffer:
vim.api.nvim_create_autocmd("BufEnter", {
nested = true,
callback = function()
if #vim.api.nvim_list_wins() == 1 and vim.bo.filetype == "NvimTree" then
vim.cmd "quit"
end
end
})
- Filtering Dotfiles and Ignored Files
To toggle between showing and hiding dotfiles dynamically:
vim.api.nvim_set_keymap('n', '<leader>d', ':lua require("nvim-tree").toggle_filter("dotfiles")<CR>', { noremap = true, silent = true })
This binds <leader>d
to toggle dotfiles visibility, giving you flexibility in real-time.