public
Last active

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

  • Download Gist
AdjustWindowHeight.vim
VimL
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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

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).

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.