summaryrefslogtreecommitdiffstats
path: root/after/ftplugin/gitcommit.lua
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-06-01 14:40:01 +0200
committerThomas Vanbesien <tvanbesi@proton.me>2026-06-01 18:55:15 +0200
commit3d5cc6433639af2757530a3099dd82f94c3bbe72 (patch)
tree60612467e2895806160337d1a0e46d4ef695af51 /after/ftplugin/gitcommit.lua
parenta8988aa9c28cf2fd47ac96b7b7a39b0ab128eeec (diff)
downloadnvim-config-3d5cc6433639af2757530a3099dd82f94c3bbe72.tar.gz
nvim-config-3d5cc6433639af2757530a3099dd82f94c3bbe72.zip
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.
Diffstat (limited to 'after/ftplugin/gitcommit.lua')
-rw-r--r--after/ftplugin/gitcommit.lua12
1 files changed, 10 insertions, 2 deletions
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 })