Simple commands to make life easier while working with git.
Those commands were already present in my config so I think moving them to new plugin will make the config cleaner and also makes it easy for me to share commands with otehrs.
| Command | Description |
|---|---|
:GitCommit |
Commit staged changes with a message |
:GitAddCommit |
Stage all changes and commit |
:GitChangeLastCommit |
Amend the last commit message |
:GitChanges / :GitOpenChangedFiles |
Open all changed files into buffers |
:DiffviewFileHistoryTelescope |
Select a file and view its history |
:DiffviewCompareBranchesTelescope |
Compare branches in diffview |
Using LazyVim:
return {
"bibekbhusal0/nvim-git-utils",
opts = {}, -- Your config here, see down for options and default settings
cmd = {
"GitAddCommit",
"GitCommit",
"GitChangeLastCommit",
"GitChanges",
"DiffviewCompareBranchesTelescope",
"DiffviewFileHistoryTelescope",
},
keys = { -- Set custom keymaps for your liking
{ "<leader>gc", ":GitAddCommit<CR>", desc = "Git add and commit" },
{ "<leader>gC", ":GitCommit<CR>", desc = "Git commit" },
{ "<leader>ge", ":GitChangeLastCommit<CR>", desc = "Git change last commit message" },
{ "<leader>gg", ":GitChanges<CR>", desc = "Git open changed files" },
{ "<leader>gdb", ":DiffviewCompareBranchesTelescope<CR>", desc = "Diffview compare branches" },
{
"<leader>gdF",
":DiffviewFileHistoryTelescope<CR>",
desc = "Diffview file history telescope",
},
},
dependencies ={
"MunifTanjim/nui.nvim", -- for commit input
"nvim-telescope/telescope.nvim", -- for diffview telescope commands
"sindrets/diffview.nvim", -- for diffview telescope commands
}
}
require("nvim-git-utils").setup({
log = { enabled = true, icon = "" },
commit_input = {
max_length = 72,
format_message = require("nvim-git-utils.utils.emojify"), -- Uses devmoji to add emojis to commit messages
hints = true,
},
})
Configure nvim-git-utils with the following options:
require("nvim-git-utils").setup({
-- Logging configuration
log = {
enabled = true, -- Enable/disable notifications. Set to false to disable all log messages
icon = "", -- Icon prefix displayed before log messages in notifications
},
-- Commit input popup configuration
commit_input = {
max_length = 72, -- Maximum character limit for commit title
-- Set to 0 or nil to disable the character counter entirely
-- Function to transform commit message before committing
-- Set to nil to disable message formatting (returns message as-is)
-- Example with devmoji (this function is also available at require("nvim-git-utils.utils.emojify")):
-- format_message = function(msg)
-- local handle = io.popen("devmoji --text " .. vim.fn.shellescape(msg))
-- local result = handle:read("*a")
-- handle:close()
-- return result:match("^%s*(.-)%s*$")
-- end,
format_message = nil,
hints = true, -- Show keyboard shortcuts hints at the bottom of the popup
-- Set to false to hide the hints bar
},
})
Main inspiration came from commitpad.nvim which allowed creating nice UI while creating new commit message with body.
Commitpad is a simple and nice plugin for creating new commit messages. This plugin has additional functionalities like:
Commitpad has a nice UI for committing but lacks customization. This plugin allows customizing:
MIT