diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-01 14:40:01 +0200 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-01 18:55:15 +0200 |
| commit | c91b60072ef3b557ae8bc0765ae99a7979add023 (patch) | |
| tree | 700f8c46a5f9dd93877454208f6507eeaaa91a0f | |
| parent | fa5e3e78b7b20985e2bf570105b388e998b89f4c (diff) | |
| download | dotfiles-c91b60072ef3b557ae8bc0765ae99a7979add023.tar.gz dotfiles-c91b60072ef3b557ae8bc0765ae99a7979add023.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.
| -rw-r--r-- | .config/nvim/after/ftplugin/gitcommit.lua | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/.config/nvim/after/ftplugin/gitcommit.lua b/.config/nvim/after/ftplugin/gitcommit.lua index 856f8bd..0f97d93 100644 --- a/.config/nvim/after/ftplugin/gitcommit.lua +++ b/.config/nvim/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 }) |
