Skip to content

Instantly share code, notes, and snippets.

@juanpabloaj
Last active September 21, 2020 22:24
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save juanpabloaj/5845848 to your computer and use it in GitHub Desktop.
Save juanpabloaj/5845848 to your computer and use it in GitHub Desktop.
Automatically fitting a quickfix window height, consider a long line as many lines. based in http://vim.wikia.com/wiki/Automatically_fitting_a_quickfix_window_height
au FileType qf call AdjustWindowHeight(3, 10)
function! AdjustWindowHeight(minheight, maxheight)
let l = 1
let n_lines = 0
let w_width = winwidth(0)
while l <= line('$')
" number to float for division
let l_len = strlen(getline(l)) + 0.0
let line_width = l_len/w_width
let n_lines += float2nr(ceil(line_width))
let l += 1
endw
exe max([min([n_lines, a:maxheight]), a:minheight]) . "wincmd _"
endfunction
@blueyed
Copy link

blueyed commented Oct 10, 2013

The loop should/can stop also already, if line('$') >= a:maxheight (and if n_lines is >= a:maxheight).

Because if there are 1000 lines, but maxheight is 10, you can just set it to 10).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment