I love UndoTree, saving me many times when I deleted/rewritten entire paragraphs but days later I realized that I needed to extract a phrase/sentence from them, without completely messing up my current version.

Goyo promotes distraction-free writing but I couldn't figure out how to use them together (without going too deep). I can start UndoTree manually or through the callbacks below but I can't switch to the the UndoTree window. This doesn't seem to be the issue with Fugitive's windows but those are not so closely coupled as the ones opened by UndoTree.

Given enough time I could get into Vim scripting and figure it out but I don't want to (and have the time right now) to reinvent the wheel and it never hurts to ask.

edit: As a workaround, I have my usual setup with UndoTree panes on the left with the main text in a window next to it, then I fire up Goyo and I can leave it by simply hitting gt to make any complicated undo manipulation but this is not ideal.

edit2: Fugitive uses preview-windows whereas UndoTree uses :new with absolute locations (the default is :topleft vertical). This absolute positioning causes the issue because opening split windows with any of the commands or with Fzf works just fine.

dirty solution:


   1 +--473 lines: =================================================
 479     " Create undotree window.
 480     if g:undotree_WindowLayout == 1 || g:undotree_WindowLayout == 2                                                                                                                                                                                                   
 481         let cmd = "topleft vertical" .                                                                                                                                                                                                                                
 482                     \self.width . ' new ' . self.bufname                                                                                                                                                                                                              
 483     else                                                                                                                                                                                                                                                              
 484         let cmd = "botright vertical" .                                                                                                                                                                                                                               
 485                     \self.width . ' new ' . self.bufname                                                                                                                                                                                                              
 486     endif                                                                                                                                                                                                                                                             
 487     call s:exec("silent keepalt ".cmd)
 493 +----------------------------------------------------------
  1. Add line let cmd = 'vertical' . self.width . ' new ' . self.bufname before if block
  2. Comment out if block


   1 "=================================================
 479     " Create undotree window.
 480     let cmd = 'vertical' . self.width . ' new ' . self.bufname                                                                                                                                                                                                        
 481     " if g:undotree_WindowLayout == 1 || g:undotree_WindowLayout == 2                                                                                                                                                                                                 
 482     "     let cmd = "topleft vertical" .                                                                                                                                                                                                                              
 483     "                 \self.width . ' new ' . self.bufname                                                                                                                                                                                                            
 484     " else                                                                                                                                                                                                                                                            
 485     "     let cmd = "botright vertical" .                                                                                                                                                                                                                             
 486     "                 \self.width . ' new ' . self.bufname                                                                                                                                                                                                            
 487     " endif                                                                                                                                                                                                                                                           
 494     -----------------------------------------------------
  1. Call :Goyo 110 in Vim
  2. Call :UndotreeToggle

Turns out I did have the time.


  • Clean up and pull request to UndoTree

  • Open issue to Goyo (CTRL-W_CTRL-W does not work properly with multiple windows)

  • those distraction free plugins use autocommands to prevent switching to the surrounding windows. You could either set eventignore option or use e.g. :noa wincmd l. But you should really open a issue at the goyo plugin to be able to have this fixed. – Christian Brabandt Oct 21 '17 at 9:40
  • I only took a crash course about vimscript since I started this yesterday so thanks for the pointers, I'll look these up. I submitted a pull request to the UndoTree repo to allow setting up custom positioning commands and the changes work with Goyo perfectly. CTRL-W_CTRL-W is a no go but CTRL-W [hjkl] work just fine. – toraritte Oct 21 '17 at 23:21

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

My .vimrc setup:

" === 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

" to automatically start UndoTree and Limelight when firing up Goyo
" (see more in Goyo project repo)
function! s:goyo_enter()
  " ...

function! s:goyo_leave()
  " ...

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

enter image description here

  • 2
    Just noting here because you are apparently too modest to do so that the custom commands you describe only exist in UndoTree because you wrote code to add them :). – Rich Oct 26 '17 at 8:48
  • If these guys hadn't written these plugins, I would still be stuck in Vim stone age. Thanks though (and also thank you for creating the proper tags:) – toraritte Oct 27 '17 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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