junegunn / vim-plug

:hibiscus: Minimalist Vim Plugin Manager
https://junegunn.github.io/vim-plug/
MIT License
33.7k stars 1.9k forks source link

Activate plugin only if executable is installed #1251

Closed mathomp4 closed 12 months ago

mathomp4 commented 12 months ago

This is just a question as I'm trying to be an elegant/better user of vim-plug rather than just hacking my way along. To wit, I recently learned about minimap.vim which requires code-minimap to be installed. Now, the author says you can do:

Plug 'wfxr/minimap.vim', {'do': ':!cargo install --locked code-minimap'}

but, well, I don't want to do any cargo install on some of the systems I run on. But, you can just install code-minimap, put it in the path, and all is well.

So, what I'd like to do is only use the plug if the executable is installed. I'm currently doing this by:

if executable('code-minimap')
    Plug 'wfxr/minimap.vim'
endif

which seems to work just fine. But I wondered "Is there a more elegant way of doing this?" vim-plug has all those cool Plug options that I'd like to learn. I tried reading the FAQ and wiki but I couldn't see anything, so apologies if this is a FAQ.


:version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jun 23 2023 15:15:13)
macOS version - arm64
Included patches: 1-1650
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl               +comments          +find_in_path      +lispindent        +multi_byte        +rightleft         +terminal          +wildignore
+arabic            +conceal           +float             +listcmds          +multi_lang        +ruby              +terminfo          +wildmenu
+autocmd           +cryptv            +folding           +localmap          -mzscheme          +scrollbind        +termresponse      +windows
+autochdir         +cscope            -footer            +lua               +netbeans_intg     +signs             +textobjects       +writebackup
-autoservername    +cursorbind        +fork()            +menu              +num64             +smartindent       +textprop          -X11
-balloon_eval      +cursorshape       +gettext           +mksession         +packages          +sodium            +timers            -xfontset
+balloon_eval_term +dialog_con        -hangul_input      +modify_fname      +path_extra        +sound             +title             -xim
-browse            +diff              +iconv             +mouse             +perl              +spell             -toolbar           -xpm
++builtin_terms    +digraphs          +insert_expand     -mouseshape        +persistent_undo   +startuptime       +user_commands     -xsmp
+byte_offset       -dnd               +ipv6              +mouse_dec         +popupwin          +statusline        +vartabs           -xterm_clipboard
+channel           -ebcdic            +job               -mouse_gpm         +postscript        -sun_workshop      +vertsplit         -xterm_save
+cindent           +emacs_tags        +jumplist          -mouse_jsbterm     +printer           +syntax            +vim9script
-clientserver      +eval              +keymap            +mouse_netterm     +profile           +tag_binary        +viminfo
+clipboard         +ex_extra          +lambda            +mouse_sgr         -python            -tag_old_static    +virtualedit
+cmdline_compl     +extra_search      +langmap           -mouse_sysmouse    +python3           -tag_any_white     +visual
+cmdline_hist      -farsi             +libcall           +mouse_urxvt       +quickfix          -tcl               +visualextra
+cmdline_info      +file_in_path      +linebreak         +mouse_xterm       +reltime           +termguicolors     +vreplace
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/Users/mathomp4/.homebrew/brew/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -I/Users/mathomp4/.homebrew/brew/Cellar/libsodium/1.0.18_1/include -D_REENTR
ANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -o vim -lm -lncurses -L/Users/mathomp4/.homebrew/brew/Cellar/libsodium/1.0.18_1/lib -lsodium -liconv -lintl -framework AppKit -L/Users/mathomp4/.
homebrew/brew/opt/lua/lib -llua5.4 -mmacosx-version-min=13.3 -fstack-protector-strong -L/Users/mathomp4/.homebrew/brew/opt/perl/lib/perl5/5.36/darwin-thread-mul
ti-2level/CORE -lperl -L/Users/mathomp4/.homebrew/brew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/config-3.11-darwin -lpython3.11
-lintl -framework CoreFoundation -lruby.3.2 -L/Users/mathomp4/.homebrew/brew/Cellar/ruby/3.2.2_1/lib
junegunn commented 12 months ago
if executable('code-minimap')
    Plug 'wfxr/minimap.vim'
endif

I think the solution is already elegant and expressive. vim-plug tries to avoid reinventing the wheel, i.e. if you can do something natively without an option, we probably shouldn't provide the option.

You might want to check out: https://github.com/junegunn/vim-plug/wiki/tips#conditional-activation