Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

winheight cannot be smaller than winminheight #4

Open
jondkinney opened this issue Mar 12, 2013 · 23 comments
Open

winheight cannot be smaller than winminheight #4

jondkinney opened this issue Mar 12, 2013 · 23 comments

Comments

@jondkinney
Copy link

Nice plugin!

I have these settings in my .vimrc courtesy of Gary Bernhardt's Destroy All Software screencast series.

set winwidth=84
" We have to have a winheight bigger than we want to set winminheight. But if
" we set winheight to be huge before winminheight, the winminheight set will
" fail.
set winheight=5
set winminheight=5
set winheight=999

When I go to load up a saved session I receive the following error:

Screen Shot 2013-03-12 at 1 05 14 PM

I'm not sure what is setting winheight=1, but that isn't in my .vimrc. Is that something this plugin is setting? It doesn't seem like it matters much, the sessions load fine, but it's obviously an eye sore / slow to have it error out each time I load up a saved session.

Thanks for taking a look!

@jondkinney
Copy link
Author

Oh, I should mention... sessions load up without error if I remove those lines from my .vimrc

@tpope
Copy link
Owner

tpope commented Mar 12, 2013

Is the fundamental problem that you are restoring a big window into a smaller one? Perhaps set sessionoptions+=resize might help.

@jondkinney
Copy link
Author

Hmm, that didn't seem to help. I think something is setting winminheight=1 in the background somewhere which is what the conflict is, I just don't know what is setting that. Not a big deal though, I'm only experimenting with that split auto-resize functionality and am leaning towards ditching it anyway. Thanks for the suggestion.

@scanny
Copy link

scanny commented Jun 5, 2013

I'm having the same problem, but I really like the (essentially) "auto-resize to make current window big" functionality that these three lines together implement. Also I love this plugin. So I'm pretty keen on finding a solution :)

In looking at the Session.vim file, it appears the "set winheight=1" line is setting things up for the lines that follow, which appear to restore the window configuration from the prior session:

set winheight=1 winwidth=1
exe 'vert 1resize ' . ((&columns * 1 + 133) / 267)
exe 'vert 2resize ' . ((&columns * 85 + 133) / 267)
exe '3resize ' . ((&lines * 3 + 38) / 76)
exe 'vert 3resize ' . ((&columns * 179 + 133) / 267)
exe '4resize ' . ((&lines * 69 + 38) / 76)
exe 'vert 4resize ' . ((&columns * 179 + 133) / 267)

I'm wondering if there's a way to perhaps change the "set winheight=1" line to something like "set winheight=minwinheight" instead? The other possibility I'm thinking is somehow make the three line winheight, minheight, winheight bit in the OP get executed after the Session.vim is finished? I don't know enough about the finer points of Vim yet, but perhaps putting it in some .after file or a special autocmd type of thingy?

Would be very grateful for the cycles of your superior Vim brain to short-circuit to an workaround or fix, otherwise I'll have to put up with it until I get further along in my Vim education :)

@scanny
Copy link

scanny commented Jun 5, 2013

Okay. I couldn't stand the suspense. I know. It's a problem. I'm working on it. :)

After noodling on the after bit for a few minutes I looked around and worked out a fix.

If you put this in your .vimrc and move the winheight/minheight lines into this autocommand group it works:

" after Vim startup -------------------- {{{
augroup at_end_of_vim_setup
    autocmd!
    autocmd VimEnter set winheight=5
    autocmd VimEnter set winminheight=3
    autocmd VimEnter set winheight=75
augroup END
" }}}

@jondkinney
Copy link
Author

@scanny nice! I'll give this a try too. Thanks for digging in :)

@jondkinney
Copy link
Author

@scanny huh, well this solution isn't working for me. I guess it stops the error messages, but then it also stops the autoresizing stuff too... any thoughts? Are you still using this?

Thanks,
Jon

@scanny
Copy link

scanny commented Aug 31, 2013

Hi Jon, no, turned out that only worked long enough for me to think it was a solution. I still get the error messages now, I've just gotten used to them :)

I tend to leave sessions up for days at a time, so it's not too big of a hardship. Sure would be nice if there was a fix though. I think it's going to take Pope cycles (distantly related to the Popemobile :) to get to the bottom of this one. Might need a post-plugin hook or something, I'm not sure who writes the Session.vim and when it gets sourced.

@jondkinney
Copy link
Author

@scanny gotcha. Say, do you use nerdtree? That really messes with opening a session for me. I know @tpope isn't a fan, but I like it :/ I've pretty much stopped using sessions because of that issue too which is unfortunate (for me anyway, lol).

@scanny
Copy link

scanny commented Aug 31, 2013

Nah, I'm all into Ctrl-P for file/buffer navigation. When I occasionally need to see the directory structure I just use :e. and navigate that way. Those two give me what I need. Sessions are big for me. I have an alias 'e' set up in zsh that opens MacVim with the Session.vim in the current dir (project dirs mostly), so sessions are a pretty important feature in my world :)

@jondkinney
Copy link
Author

Gotcha, I use ctrl-p mostly too... for some reason I just feel more comfortable seeing the directory structure on the left. Actually it helps position the code close to the center of my screen too, which is nice when editing only one buffer. Anyway, do update us if you find a solution to those loading error messages! Thanks much.

@blueyed
Copy link

blueyed commented Mar 15, 2014

FWIW, GoldenView is a plugin which might setup winminheight (initially reported for session.vim).

@hiattp
Copy link

hiattp commented Aug 16, 2014

Anyone found a good workaround or is the current thinking just to ignore the errors?

@scanny
Copy link

scanny commented Aug 16, 2014

I've moved on to meta-ignoring. I've been ignoring the errors so long now that I started ignoring the fact I ignore them :)

@lvarayut
Copy link

@scanny How do you ignore the error or did you find another way to solve it? It's very annoying!!

I tried putting silent! set winheight in my .vimrc, but still no luck :(

@boatrite
Copy link

@jondkinney @scanny @blueyed @hiattp @lvarayut I've found a way to fix this. I'll be making a PR shortly to see what @tpope thinks of this. It's probably a little hackish, and I'm not sure if there are any unintended consequences of this, but in the little testing I've done it seems to work as expected.

Inside of plugin/obsession.vim, change:

      call writefile(body, g:this_obsession)

to

      call writefile(filter(body, 'v:val != "set winheight=1 winwidth=1"'), g:this_obsession)

body is just a List, so this just filters it to remove the set winheight=1 lines.

The PR: #28

@blueyed
Copy link

blueyed commented Sep 16, 2016

@boatrite
Do you know where those lines are coming from? Is it clear from looking at the session file?

@boatrite
Copy link

@blueyed
Copy link

blueyed commented Sep 17, 2016

@boatrite
But always? (cannot check it myself)
That would new an issue then always, no? (with minwinheight)

@scanny
Copy link

scanny commented Sep 17, 2016

@boatrite: That works for me!

I patched it in on the latest master and it seems to do the needful very cleanly. I would get the message every single time, so those lines seem to be placed in the session file systematically and unconditionally.

I think it's a solid fix :)

joshukraine added a commit to joshukraine/dotfiles that referenced this issue Mar 3, 2018
The following approach avoids window size errors which tend to occur when restoring sessions.

* Store window height settings in functions.
* Before exiting Vim (VimLeavePre), reset 'winminheight' and 'winheight'
* After entering Vim (VimEnter), load custom settings.

Reference:

* tpope/vim-obsession#4
* :h 'winheight'
* :h 'winminheight'
@joshukraine
Copy link

I've battled this issue for a long time and have tried a myriad of approaches to fixing it. I believe I've found a solution which does not require any alterations to to the vim-obsession plugin. Below are the relevant parts from my .vimrc file. Hope it helps! 🙂

" Keep focus split wide, others narrow.
set winwidth=90
set winminwidth=5

" Keep focus split at max height, others minimal.
function! SetWindowHeight()
  set winheight=5
  set winminheight=5
  set winheight=999
endfunction

" Reset window height to avoid session errors.
function! ResetWindowHeight()
  set winminheight=0
  set winheight=1
endfunction

" Reset window sizes to avoid errors on session load.
augroup set_window_height
  autocmd!
  autocmd VimLeavePre * :call ResetWindowHeight()
  autocmd VimEnter * :call SetWindowHeight()
augroup END

@boatrite
Copy link

boatrite commented Mar 6, 2018

@joshukraine Nice, I just added that to my .vimrc to try it out, and it definitely works as far as I can tell. My solution stopped working a while back for what that's worth. Not sure why. Thanks!

Edit: I actually started getting a "Not enough room" error when I switched away from my branch to the regular vim-obsession. Still playing with this.

Edit 2: So I ended up with the error still even with that snippet, so I took another look at my fix. I changed it to filter by regex and get rid of any lines matching "set winheight" or "set winminheight".

master...boatrite:zb-fix-winheight-error

screenshot_5

Anyways, hope this helps any one else with this issue.

@tpope
Copy link
Owner

tpope commented Mar 17, 2018

An idea I just had:

autocmd SourcePre Session.vim set minwinheight=1
autocmd SessionLoadPost * set minwinheight=5

This is probably oversimplified, but could be another piece in the autocmd puzzle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants