C.W.K.
Stream
Lesson 03 of 04 · published

Git Integration and File Management

~11 min · neovim, git, files, oil

Level 0Trapped
0 XP0/35 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Two layers of git inside Neovim

Track 7 introduced gitsigns.nvim for inline hunks. Pair it with a heavier git client for branch operations and you cover the spectrum:

  • gitsigns.nvim — the inline layer. Hunks in the gutter, stage/reset/preview, blame inline. Best for editing loops.
  • vim-fugitive — the deep git layer. :Git as a Vim command interface to every git operation. :Git blame opens a navigable blame view; :Git log, :Git diff, :Git rebase -i all work. Best for the heavy operations.
  • Or skip both for branch ops and use lazygit in an adjacent tmux pane. Track 7's pattern.

Most people use gitsigns + lazygit. fugitive is for the people who prefer everything inside Vim.

oil.nvim — edit your filesystem like a buffer

oil.nvim is the surprise plugin everyone falls for. Open the current directory as a regular Vim buffer, and the filesystem becomes a buffer: lines are filenames, edit them with normal Vim motions, save with :w — Vim renames, moves, creates, deletes accordingly. Want to rename five files with capture-group regex? :%s/old/new/ + :w — done.

The other file-explorer school

If you prefer a sidebar tree (VS Code-like), neo-tree or nvim-tree is the alternative. Functional, familiar, but doesn't give you the buffer-as-filesystem editing power. Try oil for a week before reaching for a sidebar tree.

The minimal setup

The blocks below add gitsigns, fugitive (small footprint, doesn't activate until you call :Git), and oil. With lazy-loading, none of these slow startup; oil opens instantly when you press -.

Editing the filesystem like a buffer is the killer feature. Drag-rename in a GUI tree is fine for one file. For ten files at once, oil + visual-block editing on filenames + :w is the move. The buffer model scales; tree views don't.

Code

gitsigns.nvim — refresher from Track 7·lua
{
  "lewis6991/gitsigns.nvim",
  event = { "BufReadPost", "BufNewFile" },
  opts = {
    on_attach = function(bufnr)
      local gs = package.loaded.gitsigns
      local map = function(mode, lhs, rhs, desc)
        vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, desc = desc })
      end
      map("n", "]c", gs.next_hunk,            "Next hunk")
      map("n", "[c", gs.prev_hunk,            "Prev hunk")
      map("n", "<leader>hs", gs.stage_hunk,   "Stage hunk")
      map("n", "<leader>hr", gs.reset_hunk,   "Reset hunk")
      map("n", "<leader>hp", gs.preview_hunk, "Preview hunk")
      map("n", "<leader>hb", function() gs.blame_line({ full = true }) end, "Blame")
    end,
  },
}
vim-fugitive — deep git as Vim commands·lua
{
  "tpope/vim-fugitive",
  cmd = { "Git", "G", "Gdiffsplit", "Gblame", "Glog" },
  keys = {
    { "<leader>gs", "<cmd>Git<CR>",         desc = "Git status" },
    { "<leader>gd", "<cmd>Gdiffsplit<CR>",  desc = "Git diff (split)" },
    { "<leader>gb", "<cmd>Git blame<CR>",   desc = "Git blame" },
    { "<leader>gl", "<cmd>Git log --oneline<CR>", desc = "Git log" },
  },
}
oil.nvim — filesystem as a buffer·lua
{
  "stevearc/oil.nvim",
  cmd = "Oil",
  keys = {
    { "-", "<cmd>Oil<CR>", desc = "Open parent directory" },
  },
  opts = {
    default_file_explorer = true,
    delete_to_trash = true,
    skip_confirm_for_simple_edits = true,
    view_options = { show_hidden = true },
  },
}
neo-tree alternative — sidebar tree (use one or the other)·lua
{
  "nvim-neo-tree/neo-tree.nvim",
  cmd = "Neotree",
  dependencies = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim" },
  keys = {
    { "<leader>e", "<cmd>Neotree toggle<CR>", desc = "File tree" },
  },
  opts = { window = { width = 32 } },
}

External links

Exercise

Add oil.nvim. Press - in any buffer to open the current directory. Try renaming a file by using cw on its line and saving. Try creating a new file by adding a line and saving. Then check the filesystem (ls in a tmux pane) — your edits actually applied. If you also have gitsigns + fugitive: open a file with uncommitted changes, navigate hunks with ]c / [c, stage one with <leader>hs, then :Git to see the staged change in fugitive's status buffer.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.