avatarMichael Bao

Summary

The web content outlines the author's Neovim setup for git, detailing the use of Neogit, Gitsigns, and Diffview for efficient version control management.

Abstract

The article provides a comprehensive guide to setting up Neovim for git operations using three key plugins: Neogit, Gitsigns, and Diffview. The author, a former Doom Emacs user, appreciates the simplicity and functionality of these tools, particularly Neogit, which serves as a Magit-like interface for Neovim. The setup is managed using Lazy.nvim, a fast Neovim package manager. Neogit is praised for its essential features that facilitate committing, pushing, and pulling changes. Gitsigns is highlighted for its speed and aesthetic contribution to the coding environment, while Diffview is recognized for its utility in viewing changes, despite being used less frequently. The author encourages readers to explore these plugins and continue their journey with Neovim.

Opinions

  • The author has a positive view of Neogit, considering it a sufficient tool for their git needs, reminiscent of Magit from Doom Emacs.
  • Gitsigns is appreciated more for its visual enhancements than its functional benefits, contributing to a more pleasant coding experience.
  • Diffview is acknowledged as a useful tool for viewing changes, though it is not a primary tool in the author's workflow.
  • The author recommends these plugins to others, suggesting that they enhance the Neovim experience for git operations.
  • There is an emphasis on the ease of installation and configuration of these plugins, particularly when using Lazy.nvim as the package manager.

My Neovim Git Setup

Neogit, Gitsigns, and Diffview

Screenshot by author

Today, I will be sharing my git setup for Neovim.

I recently wrote an article on lazy.nvim, therefore the installation and configuration will be using it (instead of something like packer.nvim).

Neogit

I previously used Doom Emacs and one of my favorite plugins was Magit. It had many features that gave more information and made it easier to work with git. For me, I usually only needed to commit, push, and pull. I rarely did anything fancy, so Magit was more than enough.

Neogit is a work-in-progress clone of Magit for Neovim. Even with the current features, it is more than enough for my needs.

Screenshot of Neogit by author

Installation

return {
 "TimUntersberger/neogit",
 cmd = "Neogit",
 config = function()
  require("neogit").setup({
   kind = "split", -- opens neogit in a split 
   signs = {
    -- { CLOSED, OPENED }
    section = { "", "" },
    item = { "", "" },
    hunk = { "", "" },
   },
   integrations = { diffview = true }, -- adds integration with diffview.nvim
  })
 end,
}

The characters for section and item don’t show up, but they should work (copy/paste) with a Nerd Font. I am currently using Fira Code Nerd Font.

Keybinds

Neogit has numerous keybinds, but the ones I use the most are:

  • <C-s> Stage Everything
  • p Opens pull popup
  • P Opens push popup
  • c Opens commit popup
  • Tab Toggles diff

Gitsigns

Gitsigns is a blazingly fast plugin that adds git decorations. This plugin provides functional usage, but I mainly like it for its aesthetic.

Installation

return {
 "lewis6991/gitsigns.nvim",
 event = "BufReadPre",

 config = function()
  require("gitsigns").setup({
   signs = {
    add = { hl = "GitSignsAdd", text = "│", numhl = "GitSignsAddNr", linehl = "GitSignsAddLn" },
    change = {
     hl = "GitSignsChange",
     text = "│",
     numhl = "GitSignsChangeNr",
     linehl = "GitSignsChangeLn",
    },
    delete = { hl = "GitSignsDelete", text = "_", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" },
    topdelete = {
     hl = "GitSignsDelete",
     text = "‾",
     numhl = "GitSignsDeleteNr",
     linehl = "GitSignsDeleteLn",
    },
    changedelete = {
     hl = "GitSignsChange",
     text = "~",
     numhl = "GitSignsChangeNr",
     linehl = "GitSignsChangeLn",
    },
    untracked = { hl = "GitSignsAdd", text = "┆", numhl = "GitSignsAddNr", linehl = "GitSignsAddLn" },
   },
  })
 end,
}

All this config does is install the plugin and set the signs.

Diffview

Diffview allows effective cycling through diffs of modified files. This makes it very easy to view changes. I don’t often use diffview but it can come in handy sometimes.

Screenshot by author

Installation

return {
 "sindrets/diffview.nvim",
 cmd = { "DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles" },
}

Overall, these are the git plugins I use. The one I use the most by far is Neogit. Gitsigns is mainly for the aesthetic and diffview is useful when merging.

I would recommend giving these plugins a try and remember to keep vimming.

Linux
Git
Neovim
Software Development
Computer Science
Recommended from ReadMedium