Juanpabloaj (talk | contribs) |
|||
Line 28: | Line 28: | ||
==Comments== |
==Comments== |
||
− | For long lines |
+ | For long lines, consider a long line as many lines |
− | |||
au FileType qf call AdjustWindowHeight(3, 10) |
au FileType qf call AdjustWindowHeight(3, 10) |
||
Line 45: | Line 44: | ||
exe max([min([n_lines, a:maxheight]), a:minheight]) . "wincmd _" |
exe max([min([n_lines, a:maxheight]), a:minheight]) . "wincmd _" |
||
endfunction |
endfunction |
||
+ | " https://gist.github.com/juanpabloaj/5845848 |
Latest revision as of 17:46, 23 June 2013
Tip 1536 Printable Monobook Previous Next
created 2007 · complexity basic · author AOYAMA Shotaro · version 6.0
When I do :cw
, a quickfix window opens with a 10-line height, even when the number of errors is 1 or 2. I think it's a waste of window space.
So I wrote the following code in my vimrc. With it, a quickfix window height is automatically adjusted to fit its contents (maximum 10 lines).
au FileType qf call AdjustWindowHeight(3, 10) function! AdjustWindowHeight(minheight, maxheight) exe max([min([line("$"), a:maxheight]), a:minheight]) . "wincmd _" endfunction
Of course, this function can be applied to other windows besides the quickfix window.
If you feel it's too tight, you may want to replace line("$")
with line("$")+1
.
Comments[]
For long lines, consider a long line as many lines
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 " https://gist.github.com/juanpabloaj/5845848