Git Integration
Gitsigns (Signs in the Gutter)
{
"lewis6991/gitsigns.nvim",
config = function()
require("gitsigns").setup({
signs = {
add = { text = "│" },
change = { text = "│" },
delete = { text = "_" },
topdelete = { text = "‾" },
changedelete = { text = "~" },
},
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
local opts = { buffer = bufnr }
vim.keymap.set("n", "]h", gs.next_hunk, opts)
vim.keymap.set("n", "[h", gs.prev_hunk, opts)
vim.keymap.set("n", "<leader>hp", gs.preview_hunk, opts)
vim.keymap.set("n", "<leader>hb", gs.blame_line, opts)
vim.keymap.set("n", "<leader>hs", gs.stage_hunk, opts)
vim.keymap.set("n", "<leader>hr", gs.reset_hunk, opts)
end,
})
end,
}
Fugitive (Full Git Interface)
{
"tpope/vim-fugitive",
keys = {
{ "<leader>gs", "<cmd>Git<cr>", desc = "Git status" },
},
}
Fugitive provides :Git (or :G), which opens a git status window. From there you can:
- Stage files with
-(in the status window) - Commit with
cc - Diff with
dd - Push with
:Git push
Sessions and Persistence
Vim Sessions
Sessions save your entire editing state: open files, window layout, cursor positions.
:mksession ~/mysession.vim " Save session
:source ~/mysession.vim " Restore session
nvim -S ~/mysession.vim " Restore session on startup
Persisted.nvim (Automatic Sessions)
{
"olimorris/persisted.nvim",
config = function()
require("persisted").setup({
save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"),
autoload = true, -- Auto-load session on startup
})
end,
}
Undo Persistence
vim.opt.undofile = true -- in init.lua
This saves your undo history across sessions. You can undo changes even after closing and reopening a file.