3

I have Neovim setup with configurations for file types separated into ftplugin files.

I would like to have Neovim start the Goyo plugin when I open a markdown file. However, I would like to keep this logic outside of my init.vim for cleanliness.

I have a markdown config located in ...nvim/ftplugin/markdown.vim. Neovim is able to read it.

Should I use autocmd? Or is there another method for doing this that is cleaner and easier? Also any references to the correct help pages in Neovim would be greatly appreciated!

3
  • 1
    Consider the Vi and Vim site for questions on Vim and NeoVim!
    – filbranden
    Commented Sep 6, 2020 at 2:38
  • @filbranden That's a great idea. I'm going to post it there too.
    – Eugene Grechko
    Commented Sep 6, 2020 at 17:42
  • Instead, you can ask a moderator of this site to migrate it there.
    – filbranden
    Commented Sep 6, 2020 at 17:46

1 Answer 1

4

You don't need to use an autocmd or anything, because the scripts under ftplugin are already loaded by an autocmd triggered when the filetype is actually set.

For example, for filetype markdown, the autocmd that loads ftplugin is equivalent to:

autocmd FileType markdown runtime! ftplugin/markdown.vim ftplugin/markdown_*.vim ftplugin/markdown/*.vim

So you can simply add a command, such as Goyo, to enable Goyo, inside such an ftplugin script.

Note that you can use a ftplugin/markdown.vim file, but if one already exists, you can also create a file named ftplugin/markdown_goyo.vim or ftplugin/markdown/goyo.vim, any and all of those will be loaded when a file with filetype markdown is opened.

If you want to have the Goyo command opened late, after all other ftplugin commands for that filetype have been executed (to prevent any interference and override all previous settings), then store it under ~/.config/nvim/after/ftplugin rather than ~/.config/nvim/ftplugin. The after subdirectory is added last to 'runtimepath', so the scripts stored there are executed last.

You'll find relevant documentation under :help filetype-plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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