Browse Source

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.
Lifepillar 9 years ago
parent
commit
bf63188066
1 changed files with 8 additions and 4 deletions
  1. 8 4
      plugin/youcompleteme.vim

+ 8 - 4
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()