Back to Blog

Neovim Series Finale: neo-tree File Explorer & gitsigns Git Workflow | Episode 12

Sandy LaneSandy Lane

Video: Neovim Series Finale: neo-tree File Explorer & gitsigns Git Workflow | Episode 12 by Taught by Celeste AI - AI Coding Coach

Watch full page →

Neovim Series Finale: neo-tree File Explorer & gitsigns Git Workflow

In this final episode of the Neovim series, we integrate powerful plugins to enhance project navigation and git management directly inside Neovim. You'll learn how to configure neo-tree.nvim as a sidebar file explorer with file operations, and set up gitsigns.nvim to visualize and interact with git changes inline, enabling a seamless git workflow without leaving the editor.

Code

-- lua/neovim-config.lua

-- Setup for neo-tree.nvim (file explorer)
require("neo-tree").setup({
  close_if_last_window = true,
  popup_border_style = "rounded",
  enable_git_status = true,
  enable_diagnostics = false,
  default_component_configs = {
    icon = {
      folder_closed = "",
      folder_open = "",
      folder_empty = "ﰊ",
      default = "",
    },
    git_status = {
      symbols = {
        added     = "✚",
        modified  = "",
        deleted   = "✖",
        renamed   = "",
        untracked = "",
        ignored   = "",
        unstaged  = "",
        staged    = "",
        conflict  = "",
      },
    },
  },
  window = {
    position = "left",
    width = 30,
    mappings = {
      [""] = "open",
      ["a"] = "add",
      ["r"] = "rename",
      ["d"] = "delete",
      ["e"] = "toggle_hidden",
    },
  },
  filesystem = {
    follow_current_file = true,
    use_libuv_file_watcher = true,
  },
})

-- Keymaps to toggle and reveal neo-tree
vim.api.nvim_set_keymap("n", "e", ":Neotree toggle", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "E", ":Neotree reveal", { noremap = true, silent = true })

-- Setup for gitsigns.nvim (git integration)
require('gitsigns').setup({
  signs = {
    add          = { hl = 'GitGutterAdd', text = '│' },
    change       = { hl = 'GitGutterChange', text = '│' },
    delete       = { hl = 'GitGutterDelete', text = '_' },
    topdelete    = { hl = 'GitGutterDelete', text = '‾' },
    changedelete = { hl = 'GitGutterChange', text = '~' },
  },
  on_attach = function(bufnr)
    local gs = package.loaded.gitsigns
    local opts = {buffer = bufnr, noremap=true, silent=true}

    -- Navigation between hunks
    vim.keymap.set('n', ']h', gs.next_hunk, opts)
    vim.keymap.set('n', '[h', gs.prev_hunk, opts)

    -- Actions
    vim.keymap.set('n', 'hs', gs.stage_hunk, opts)
    vim.keymap.set('n', 'hr', gs.reset_hunk, opts)
    vim.keymap.set('n', 'hp', gs.preview_hunk, opts)
    vim.keymap.set('n', 'hb', gs.blame_line, opts)
    vim.keymap.set('n', 'tb', gs.toggle_current_line_blame, opts)
    vim.keymap.set('n', 'hd', gs.diffthis, opts)
  end,
})

-- Telescope git status picker (optional)
vim.api.nvim_set_keymap('n', 'gs', ":Telescope git_status", { noremap = true, silent = true })

Key Points

  • neo-tree.nvim provides a versatile file explorer sidebar with intuitive file operations like add, rename, delete, and open.
  • Enabling follow_current_file and file_watcher keeps the explorer in sync with your active buffer and filesystem changes.
  • gitsigns.nvim adds inline git change markers and buffer-local keymaps for staging, resetting, previewing hunks, blaming lines, and toggling blame annotations.
  • Custom keybindings streamline navigation between git hunks and integrate git actions seamlessly within Neovim.
  • Using Telescope's git status picker complements the workflow by allowing fuzzy searching of changed files from the terminal.