Add diffview

Use instead of fugitive for easy staging
This commit is contained in:
2023-09-20 00:51:49 +02:00
parent 71c6cee017
commit 665c298cd8
4 changed files with 97 additions and 4 deletions
+2 -1
View File
@@ -11,13 +11,14 @@
"cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" },
"diffview.nvim": { "branch": "main", "commit": "a111d19ccceac6530448d329c63f998f77b5626e" },
"friendly-snippets": { "branch": "main", "commit": "ebf6d6e83494cdd88a54a429340256f4dbb6a052" },
"gitsigns.nvim": { "branch": "main", "commit": "bce4576a9047085a528c479a7fe1e2f6b787b6c1" },
"indent-blankline.nvim": { "branch": "master", "commit": "9637670896b68805430e2f72cf5d16be5b97a22a" },
"lazy.nvim": { "branch": "main", "commit": "2a9354c7d2368d78cbd5575a51a2af5bd8a6ad01" },
"lspkind.nvim": { "branch": "master", "commit": "57610d5ab560c073c465d6faf0c19f200cb67e6e" },
"lualine.nvim": { "branch": "master", "commit": "45e27ca739c7be6c49e5496d14fcf45a303c3a63" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "f014db32437aa61c86fc0ef1067cd2bc6a37205c" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "2451adb9bdb0fd32140bf3aa8dbc17ff60050db3" },
"mason-update-all": { "branch": "main", "commit": "007a4085fe5e830b9139313652e1553bf1a9b857" },
"mason.nvim": { "branch": "main", "commit": "d66c60e17dd6fd8165194b1d14d21f7eb2c1697a" },
"move.nvim": { "branch": "main", "commit": "d663b74b4e38f257aae757541c9076b8047844d6" },
+81
View File
@@ -0,0 +1,81 @@
--[[
Copyright 2023 Oscar Wallberg
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
-- https://github.com/sindrets/diffview.nvim
local actions = require("diffview.actions")
require("diffview").setup({
enhanced_diff_hl = true,
view = {
default = {
layout = "diff3_mixed",
winbar_info = true,
},
merge_tool = {
layout = "diff3_mixed",
disable_diagnostics = true,
winbar_info = true,
},
file_history = {
layout = "diff2_horizontal",
winbar_info = true,
},
},
default_args = {
DiffviewOpen = { "--imply-local", },
},
keymaps = {
file_panel = {
{
"n",
"<CR>",
function()
actions.select_entry()
vim.fn.execute("wincmd l")
end,
{ desc = "Focus the diff for the selected entry", },
},
{
"n",
"s",
actions.toggle_stage_entry,
{ desc = "Stage / unstage the selected entry", },
},
{
"n",
"u",
actions.toggle_stage_entry,
{ desc = "Stage / unstage the selected entry", },
},
{
"n",
"cc",
":G commit | wincmd J<CR>",
{ desc = "Commit staged changes", },
},
{
"n",
"ca",
":G commit --amend | wincmd J<CR>",
{ desc = "Amend the last commit", },
},
},
},
})
local opts = { silent = true, remap = false, }
vim.keymap.set("n", "<leader>gg", ":DiffviewOpen<CR>", opts)
+7 -3
View File
@@ -22,6 +22,10 @@ local function git_status_tab()
vim.fn.execute("vertical resize 60 | set wfw")
end
vim.keymap.set("n", "<leader>gd", ":Gdiffsplit<CR>", { remap = false, })
vim.keymap.set("n", "<leader>gg", git_status_tab, { silent = true, remap = false, })
vim.keymap.set("n", "<leader>gc", ":G commit<CR>", { remap = false, })
local opts = { silent = true, remap = false, }
vim.keymap.set("n", "<leader>gd", ":Gdiffsplit<CR>", opts)
-- Only used if diffview is not available
if not pcall(require, "diffview") then
vim.keymap.set("n", "<leader>gg", git_status_tab, opts)
end
+7
View File
@@ -226,6 +226,13 @@ local plugins = {
{
"farmergreg/vim-lastplace",
},
{
"sindrets/diffview.nvim",
config = function () require("plugins.config.diffview") end,
dependencies = {
"nvim-tree/nvim-web-devicons",
},
},
}
local opts = {}