From 3d5cc6433639af2757530a3099dd82f94c3bbe72 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Mon, 1 Jun 2026 14:40:01 +0200 Subject: misc(nvim): smart split git diff window in gitcommit files Split the window horizontally when there is not enough columns on the screen to display the cached git diff comfortably. --- after/ftplugin/gitcommit.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'after/ftplugin/gitcommit.lua') diff --git a/after/ftplugin/gitcommit.lua b/after/ftplugin/gitcommit.lua index 856f8bd..0f97d93 100644 --- a/after/ftplugin/gitcommit.lua +++ b/after/ftplugin/gitcommit.lua @@ -15,10 +15,18 @@ vim.api.nvim_create_autocmd("BufWinEnter", { group = vim.g.dotfiles.augroup, buffer = 0, callback = function() + local MIN_COL_FOR_VERTICAL_SPLIT = 200 + local vert_split = vim.o.columns >= MIN_COL_FOR_VERTICAL_SPLIT local gitcommit_window = vim.api.nvim_get_current_win() - -- Open cached diff window + -- Open cached diff window (see `:help ft-gitcommit-plugin`) vim.cmd.DiffGitCached() - vim.cmd.wincmd("L") + vim.opt_local.winfixwidth = false + vim.opt_local.winfixheight = false + if vert_split then + vim.cmd.wincmd("L") + else + vim.cmd.wincmd("J") + end -- Enable English spell check in the original window -- If `'spell'` is set before `:DiffGitCached` it propagates to the cached diff window (that we don't want) vim.api.nvim_set_option_value("spell", true, { win = gitcommit_window }) -- cgit v1.3.1