Run / Toggle Command for Certain File Types Only
I found this nice distraction free letter plugin called Goyo , which is really well done. I'm configuring autocmds
to include Goyo based on file type. So if I am working on a markdown or text file, Goyo will automatically initialize. If I leave the buffer or change the file type, then Goyo will be closed. Below is how I implemented the behavior:
autocmd FileType * :Goyo!
autocmd FileType markdown :Goyo
autocmd FileType text :Goyo
It seems to work. The question is: or not, is this the way to go or if there is a better approach to solving the problem?
source to share
This is just fine and how would I implement it. Since you are only hooking to the event FileType
, the switch is only triggered on a :edit
new file, not when an existing buffer is called with a different file type. You can do it with BufWinEnter
, but it can cause too many unintended requests. My guess is that the plugin comes with a quick display switch to manually do this. Anyway.
Alternative
An alternative to commands autocmd FileType
are file type plugins (i.e. ~/.vim/ftplugin/markdown.vim
, etc.), which have the advantage of separating things neatly. But since you need autorun for everyone to turn off Goyo, and the list of file types is small, I would also prefer to keep things together as you do.
Improvements
Note that a duplicate set of auto-coders will be added to your command set if you return :source
yours ~/.vimrc
(or whatever script you put them in). To avoid this, you can wrap them in
augroup AutomaticGoyo
autocmd!
...
augroup END
source to share