From bf63188066c0cbe9a469bfd7e0d8b695c50f33f8 Mon Sep 17 00:00:00 2001 From: Lifepillar Date: Sat, 26 Mar 2016 21:11:11 +0200 Subject: [PATCH] Support lazy loading with :packadd. Vim recently has introduced a new feature called 'packages', which permits, among the rest, to disable automatic loading a plugin at startup. Plugins that are disabled at startup may be manually loaded during a session using :packadd (see :h packages, :h :packadd). Of course, a plugin that is loaded after startup cannot rely on VimEnter events. In order to support lazy loading YCM, check whether YCM is sourced during startup or at a later time. In the former case, define an autocommand as before; in the latter case, enable YCM immediately. --- plugin/youcompleteme.vim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugin/youcompleteme.vim b/plugin/youcompleteme.vim index 8e5ebc25..1163bb15 100644 --- a/plugin/youcompleteme.vim +++ b/plugin/youcompleteme.vim @@ -165,10 +165,14 @@ let g:ycm_disable_for_files_larger_than_kb = " On-demand loading. Let's use the autoload folder and not slow down vim's " startup procedure. -augroup youcompletemeStart - autocmd! - autocmd VimEnter * call youcompleteme#Enable() -augroup END +if has( 'vim_starting' ) " loading at startup + augroup youcompletemeStart + autocmd! + autocmd VimEnter * call youcompleteme#Enable() + augroup END +else " manual loading with :packadd + call youcompleteme#Enable() +endif " This is basic vim plugin boilerplate call s:restore_cpo()