Today I wrote this little utility function to resize my current window to a comfortable width:
-- Resizes the current window to the maximum required width
function M.resize_window()
local padding = 7
local lines_count = vim.api.nvim_buf_line_count(0)
local lines = vim.api.nvim_buf_get_lines(0, 0, lines_count, false)
local longerLine = 0
for _, line in ipairs(lines) do
local new_len = string.len(line) or 0
if new_len > longerLine then
longerLine = new_len
end
end
local cmd = (longerLine + padding) .. "wincmd |"
vim.api.nvim_command(cmd)
end
As you can see, I just hardcoded some padding to a value of 7. Any way to know what value should I put as padding instead of that fixed 7 ? I guess this has to do with decorations like line-numbers, relative numbers and that stuff.
winwidth()
to calculate a padding (or just use a hard-coded value, if this is comfortable for you)