Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Automatically fitting a quickfix window height, consider a long line as many lines. based in
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
exe max([min([n_lines, a:maxheight]), a:minheight]) . "wincmd _"

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
Something went wrong with that request. Please try again.