Skip to content
Attila Gulyas edited this page Oct 22, 2017 · 23 revisions

Callbacks for GVim

function! s:goyo_enter()
  if has('gui_running')
    set fullscreen
    set background=light
    set linespace=7
  elseif exists('$TMUX')
    silent !tmux set status off
  endif
endfunction

function! s:goyo_leave()
  if has('gui_running')
    set nofullscreen
    set background=dark
    set linespace=0
  elseif exists('$TMUX')
    silent !tmux set status on
  endif
endfunction

autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()

Disabling plugins

MiniBufExpl with g:miniBufExplBuffersNeeded set

function! s:goyo_enter()
  MBEClose
  wincmd w
endfunction

autocmd! User GoyoEnter call <SID>goyo_enter()

ZoomWin

function! s:goyo_enter()
  delcommand ZoomWin
  delcommand <Plug>ZoomWin
endfunction

function! s:goyo_leave()
  command! ZoomWin call ZoomWin()
  command! <Plug>ZoomWin call ZoomWin()
endfunction

autocmd! User GoyoEnter call <SID>goyo_enter()
autocmd! User GoyoLeave call <SID>goyo_leave()

Ensure :q to quit even when Goyo is active

Suggested by mm2703 and axelGschaider in #16

function! s:goyo_enter()
  let b:quitting = 0
  let b:quitting_bang = 0
  autocmd QuitPre <buffer> let b:quitting = 1
  cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
endfunction

function! s:goyo_leave()
  " Quit Vim if this is the only remaining buffer
  if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
    if b:quitting_bang
      qa!
    else
      qa
    endif
  endif
endfunction

autocmd! User GoyoEnter call <SID>goyo_enter()
autocmd! User GoyoLeave call <SID>goyo_leave()

Setup to use it together with UndoTree

UndoTree layouts use absolute positioning commands by default (topleft,botright) but it can be configured to accept custom ones. (stackexchange)

" === UndoTree
" using relative positioning instead
let g:undotree_CustomUndotreeCmd = 'vertical 32 new'
let g:undotree_CustomDiffpanelCmd= 'belowright 12 new'

" === Goyo
" changing from the default 80 to accomodate for UndoTree panel
let g:goyo_width = 104