junegunn / vim-plug

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

[question] How to install plugins locally and also use the system wide plugins like what pip does for Python packages? #903

Open jdhao opened 4 years ago

jdhao commented 4 years ago

I want to set up neovim for all users of my Linux server, and I use vim-plug to manage the plugins.

The part about plugin installation is something like the following:

let g:PLUGIN_HOME="/usr/local/share/nvim/site"                    

call plug#begin(g:PLUGIN_HOME)                                                                                  
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }         

Plug 'zchee/deoplete-jedi', { 'for': 'python' }                       

Plug 'Shougo/neco-vim', { 'for': 'vim' }  

call plug#end()                           

This works fine and will install plugins into /usr/local/share/nvim/site. All users can use these plugins under their account.

The problem is that I do not know how to let the users also use vim-plug to install other plugins they want to use.

For example, suppose a user want to install ayu-vim, if they use Plug 'ayu-theme/ayu-vim' in ~/.config/nvim/init.vim and then use :PlugInstall. vim-plug warns that the user does not have permission to install plugins under /usr/local/share/nvim/site.

If the user choose to use:

call plug#begin('/home/username/.local/share/nvim/plugged')
Plug 'ayu-theme/ayu-vim'
call plug#end()

Only this plugin will take effect, and all other plugins under /usr/local/share/nvim/site does not work anymore.

Of course, the user can install the plugin manually and update the runtimepath variable manually. But it would be preferable to use vim-plug to manage the plugins.

I am thinking of a functionality similar to how pip manages user and global packages, i.e., the user can choose to install plugins locally if he does not have root rights. In this way, the user can use both system-wide plugins and also user-specific plugins.

Is there an easy to achieve this right now?

janlazo commented 4 years ago

Related: https://github.com/junegunn/vim-plug/issues/657

jdhao commented 4 years ago

That question asks how to install plugins for all the users. My question is about how the user can install their own plugins using vim-plug and also use the system-wide ones.

janlazo commented 4 years ago
" /usr/share/vim/vim74/autoload/jdhao.vim
let s:base_dir = expand('<sfile>:p:h:h')

function jdhao#load_system_plugs()
  " local plugs installed via OS package manager
  if isdirectory(s:base_dir . '/plugged/vim-foo')
    call plug#(s:base_dir . '/plugged/vim-foo', {})
  endif 
  if isdirectory(s:base_dir . '/plugged/vim-bar')
    call plug#(s:base_dir . '/plugged/vim-bar', {})
  endif
endfunction
" vimrc
call plug#begin('~/.vim/plugged')
call jdhao#load_system_plugs()
Plug 'lifepillar/vim-gruvbox8'
call plug#end()
jdhao commented 4 years ago

Thanks for the hint. But this becomes impractical since I have installed more than 60 plugins in the system. I will find if I can make it work.