summaryrefslogtreecommitdiff
path: root/nvim/lua/config/man.lua
blob: 0c0357c52cc0cabeb7d92b99bc3a714612c37ba9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
vim.api.nvim_create_autocmd({ "FileType", "VimResized" }, {
  pattern = "man",
  callback = function()
    -- Read MANWIDTH from environment or fallback to 80 if not set
    local manwidth_env = os.getenv("MANWIDTH")
    local target_width = tonumber(manwidth_env) or 80

    -- Calculate padding to center the text
    local win_width = vim.api.nvim_win_get_width(0)
    local padding = math.max(0, math.floor((win_width - target_width) / 2))
	local nu_offset = vim.wo.numberwidth or 0
	local final_padding = math.max(0, padding - nu_offset)

	vim.opt_local.statuscolumn = string.rep(" ", final_padding) .. "%=%{v:lnum} "

	-- disable wrapping only for centered view
	if final_padding > 0 then
		vim.opt_local.wrap = false
	else
		vim.opt_local.wrap = true
	end
  end,
})