3

I found this nice plugin for distraction free writing named Goyo, which is really well done. I setup autocmds to enable Goyo based on the filetype, so if I work on a markdown or textfile Goyo gets initialized automatically. If I leave the buffer or change the filetype then Goyo gets closed. Below is how I implemented the behaviour:

autocmd FileType * :Goyo!
autocmd FileType markdown :Goyo
autocmd FileType text :Goyo

That seems to work fine. The question is, whether or not this is the way to go or if there is a better approach to solve the problem?

Tristan Hessell
  • 930
  • 10
  • 21
Saucier
  • 4,200
  • 1
  • 25
  • 46
  • So I tried exactly the same thing and got ``` Error detected while processing function lightline#update_disable: line 1: E121: Undefined variable: s:lightline ``` I'm running lightline as well, do you know any possible fixes ? – Abhai Kollara Sep 30 '18 at 14:39

1 Answers1

4

That's just fine and how I would implemented it, too. As you only hook into the FileType event, the toggling is only triggered when you :edit a new file, not when you recall an existing buffer with another filetype. You could do that with BufWinEnter, but it may cause too many inadvertent togglings. I guess the plugin comes with a quick toggle mapping to manually do this, anyway.

Alternative

An alternative to the autocmd FileType commands is filetype plugins (i.e. ~/.vim/ftplugin/markdown.vim etc.), which have the benefit of separating things neatly. But as you need a catch-all autocmd to turn off Goyo, and the list of filetypes is small, I would also prefer keeping things together, just like you did.

Improvements

Note that your set of commands would add a duplicate set of autocmds if you re-:source your ~/.vimrc (or whichever script you've put them in). To avoid that, you could wrap them in

augroup AutomaticGoyo
    autocmd!
    ...
augroup END
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Thanks a lot for you review! Good that you pointed me to `augroup` I almost forgot it since I was absent from vimscript for a while. :) – Saucier Dec 06 '14 at 12:43