My Neovim Git Setup
Neogit, Gitsigns, and Diffview
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.
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 Everythingp
Opens pull popupP
Opens push popupc
Opens commit popupTab
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.
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.