1

I have the following code in my vimrc

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

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?

5

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!
endfun

augroup custom_vimrc
  autocmd!
  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 at 23:42

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.