2

I have a file that is 9 lines long called foo.txt . I use

:split foo.txt 

and the new split takes up a full 50% of the editor, which results in a lot of wasted space.

I can resize it with :resize ctrl-R=line('$') but I have to type it manually each time the file changes because the editor only remembers the evaluated value.

So my question is:

  • Is it possible to open a split with maximum height to be the size of the file
  • Is it possible to have this happen dynamically, so the size of the split changes (to some maximum) as I add and remove lines.

1 Answer 1

5

Possibly something like

augroup resizer
  autocmd!
  autocmd TextChanged * execute 'resize' line('$')
  autocmd TextChangedI * execute 'resize' line('$')
augroup end

which should resize the current window as the text is changed (but this may be slow, performance-wise: an alternative would perhaps be TextChanged + InsertLeave).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.