junegunn / goyo.vim

:tulip: Distraction-free writing in Vim
MIT License
4.52k stars 118 forks source link

Is it possible to use the tmux height instead of the vim height? #202

Open Falkgaard opened 5 years ago

Falkgaard commented 5 years ago

Hi, love the plugiN!

If I have my tmux split vertically I get full height when I go into distraction free mode, but if my Vim is run in a horizontal split, the height becomes relative to that pane (even though Goyo + tmux zoom lets me fullscreen it). Is it possible to use the tmux height instead of the vim height?

mrolli commented 2 years ago

I also just landed here with my goyo setup. Apparently the height of the available space is calculated and applied before the other tmux pane has gone and the vim pane is the sole, maximized pane visible. It would be really great if the sequence of action would be the other way round or if a recalculation of the height could take place.

TimDeve commented 2 years ago

@mrolli Agree that a s:goyo_pre_enter hook would be nice.

Old solution

Edit:

Newer solution that waits until tmux has zoomed in before forcing Goyo to redraw, it looks pretty much instant in action.

function! s:goyo_enter()
  if g:is_in_tmux
    silent !tmux set status off
    silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z

    let l:timeout = reltimefloat(reltime()) + 0.5
    while reltimefloat(reltime()) < l:timeout
      let l:res = system("sh -c \"tmux list-panes -F '#{E:window_zoomed_flag}' | head -c 1\"")
      sleep 1m
      if l:res == '1'
        break
      endif
    endwhile

    " Need to pass default width (80) to Goyo to tell
    " it to turn on rather than toggle.
    execute 'Goyo 80'
  endif

  set noshowmode
  set noshowcmd
  set scrolloff=999

  Limelight
endfunction

It uses reltime + reltimefloat which is only in nvim I believe, but that can be replaced with a for loop instead.