I want to write a function that I can call from a map. The idea is to resize the window to fit the contents of the buffer. This is not too complicated:
fu! ResizeWindow(vert) "{{{
if a:vert
let longest = max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
exec "vertical resize " . (longest+4)
else
exec 'resize ' . line('$')
1
endif
endfu "}}}
However, I would like the function to take logical lines into account when calculating the height (I'm not too worried about the width).
For example, a line that is wrapped (due to :set wrap) will be considered two or more lines. A block of 37 lines that add up will be considered only one.
- " ", ? , - , , ?