I have the following code in my vimrc

if exists(":Goyo")
    augroup LatexGoyo
        autocmd BufReadPost,BufNewFile *.tex Goyo
    augroup END
    augroup LatexColumnSet
        autocmd FileType tex setlocal columns=100
    augroup END

The idea is to check for the presence of the Goyo command provided by the goyo.vim plugin, and then invoke it upon opening any tex file. If this plugin is not available/installed, then I'd like to set the columns to 100.

However, with these settings in my vimrc, when opening a tex file, the Goyo command is not executed.

What am I doing wrong, and how to fix this?


The problem is, your vimrc file is executed before any plugins are loaded. You can check the order of what source files are loaded by issueing the :scriptnames command.

The usual way to fix this problem is to execute the test inside a VimEnter autocommand, something like this:

function s:init()
   " do your test here!

augroup custom_vimrc
  autocmd VimEnter * call s:init
augroup end
  • Another possibility is to do that from a ~/.vim/after/plugin/*.vim which runs after normal plugins are loaded.
    – filbranden
    Sep 12 '19 at 23:42

There are two possibilities:

  • Move the check to after plugins have been loaded, e.g. by hooking into the VimEnter event, as outlined by @ChristianBrabandt's answer.
  • Force early loading of the plugin:
runtime! plugin/goyo.vim    " Try loading the plugin.
if exists(":Goyo")
    " ...

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.