Skip to main content

Overview

NvimTree is a file explorer plugin that provides a tree-style view of your project’s file structure. It replaces Neovim’s built-in netrw with a more feature-rich and performant alternative. Plugin: nvim-tree/nvim-tree.lua

Features

  • Tree-style file explorer with icons
  • Relative line numbers for quick navigation
  • Git status integration
  • Indent markers for better visibility
  • Custom folder arrow icons
  • File operations (create, delete, rename, copy)
  • Integration with window splits

Configuration

NvimTree is configured in lua/magictt/plugins/nvim-tree.lua:
return {
  "nvim-tree/nvim-tree.lua",
  dependencies = "nvim-tree/nvim-web-devicons",
  config = function()
    local nvimtree = require("nvim-tree")

    -- Disable netrw (recommended by nvim-tree)
    vim.g.loaded_netrw = 1
    vim.g.loaded_netrwPlugin = 1

    nvimtree.setup({
      view = {
        width = 35,
        relativenumber = true,
      },
      renderer = {
        indent_markers = {
          enable = true,
        },
        icons = {
          glyphs = {
            folder = {
              arrow_closed = "",
              arrow_open = "",
            },
          },
        },
      },
      actions = {
        open_file = {
          window_picker = {
            enable = false,  -- Better split integration
          },
        },
      },
      filters = {
        custom = { ".DS_Store" },
      },
      git = {
        ignore = false,  -- Show gitignored files
      },
    })
  end
}

Keybindings

Global Keymaps

KeymapCommandDescription
<leader>ee:NvimTreeToggleToggle file explorer
<leader>ef:NvimTreeFindFileToggleToggle explorer on current file
<leader>ec:NvimTreeCollapseCollapse all folders
<leader>er:NvimTreeRefreshRefresh file explorer

Inside NvimTree Window

When the NvimTree window is focused, you can use these default keybindings:
KeyAction
j/kMove down/up
<CR>Open file or expand/collapse folder
oOpen file or folder
PGo to parent directory
<BS>Close directory
-Navigate to parent directory

File Operations

KeyAction
aCreate new file or directory (end with /)
dDelete file or directory
rRename file or directory
xCut file or directory
cCopy file or directory
pPaste file or directory
yCopy file name
YCopy relative path
gyCopy absolute path

View Options

KeyAction
HToggle hidden files
IToggle gitignore files
RRefresh tree
WCollapse all folders
EExpand all folders
g?Show help (all keybindings)

Window Management

KeyAction
<C-v>Open file in vertical split
<C-x>Open file in horizontal split
<C-t>Open file in new tab
qClose NvimTree window

Usage Examples

Toggle File Explorer

Press <leader>ee to open/close the file explorer:
vim.keymap.set("n", "<leader>ee", "<cmd>NvimTreeToggle<CR>", 
  { desc = "Toggle file explorer" })

Find Current File

Press <leader>ef to open the explorer and highlight the current file:
vim.keymap.set("n", "<leader>ef", "<cmd>NvimTreeFindFileToggle<CR>", 
  { desc = "Toggle file explorer on current file" })
This is useful when you’re editing a file and want to see where it is in the project structure.

Collapse All Folders

Press <leader>ec to collapse all expanded folders:
vim.keymap.set("n", "<leader>ec", "<cmd>NvimTreeCollapse<CR>", 
  { desc = "Collapse file explorer" })

Refresh Tree

Press <leader>er to refresh the file tree (useful after external changes):
vim.keymap.set("n", "<leader>er", "<cmd>NvimTreeRefresh<CR>", 
  { desc = "Refresh file explorer" })

Tips and Tricks

Creating Files and Directories

Press a in NvimTree to create:
  • File: Type filename and press Enter: newfile.lua
  • Directory: Type name ending with /: newfolder/
  • Nested structure: Type full path: src/components/Button.tsx

Git Integration

NvimTree shows git status with icons:
  • - Staged changes
  • - Unstaged changes
  • - Untracked files
  • - Renamed files
The config shows gitignored files (controlled by git.ignore = false).

Relative Line Numbers

The explorer uses relative line numbers (configured with relativenumber = true), making it easy to jump to files using motions like 10j or 5k.

Working with Splits

The configuration disables window picker for better split behavior:
  • Files open in the last active window
  • Use <C-v> for vertical split
  • Use <C-x> for horizontal split

Copy File Paths

Quickly copy file paths:
  • y - Copy just the filename
  • Y - Copy relative path from project root
  • gy - Copy absolute path

Filtering Files

The config filters out .DS_Store files automatically. Show/hide other files:
  • H - Toggle hidden files (files starting with .)
  • I - Toggle gitignored files

Customization Tips

Change Tree Width

Modify the width setting in nvim-tree.lua:
view = {
  width = 40,  -- Change from default 35
}

Different Folder Icons

Customize the folder arrows:
icons = {
  glyphs = {
    folder = {
      arrow_closed = "▶",
      arrow_open = "▼",
    },
  },
}

Filter Additional Files

Add more files to filter:
filters = {
  custom = { ".DS_Store", "node_modules", ".git" },
}

Auto-close on File Open

To close NvimTree when opening a file:
actions = {
  open_file = {
    quit_on_open = true,
  },
}

Integration with Alpha Dashboard

NvimTree is integrated into the Alpha dashboard:
  • Press Space ee from the dashboard to open the file explorer
  • The dashboard button uses the same command as the global keymap
  • Telescope - Fuzzy file finder alternative
  • Alpha - Dashboard with NvimTree shortcut

Troubleshooting

No file icons showing
  • Install a Nerd Font and configure your terminal to use it
  • Check nvim-web-devicons is loaded: :Lazy
NvimTree doesn’t open
  • Check for errors: :messages
  • Verify netrw is disabled: :echo g:loaded_netrw
Git status not showing
  • Ensure you’re in a git repository
  • Check git is installed: git --version
  • Verify git integration is enabled in config
Relative numbers not showing
  • Check your Neovim version (requires 0.7+)
  • Verify the config has relativenumber = true

Build docs developers (and LLMs) love