I am trying to containerize vim along with the plugins. I am using singularity containers. The most important plugin is youcompleteme. My approach to containerizing the plugins is to install vim and clone all the plugins to /etc/vim/plugin
and compile youcompleteme during the build.
Once the image is built, I launch vim with the modified runtimepath (rtp)
that points to /etc/vim
:
singularity run vim_image.sif vim --cmd 'set rtp^=/etc/vim'
But, vim is failing to load the plugins. I am getting errors like:
Error detected while processing /etc/vim/plugin/sonokai/autoload/airline/themes/sonokai.vim: line
10: E117: Unknown function: sonokai#get_configuration line 11: E121: Undefined variable: s:configuration E116: Invalid arguments for function sonokai#get_palette(s:configuration.style, s:configuration.colors_override)...
I expect vim to load any plugins inside /etc/vim/plugin
without any issues. I am stuck on this. Any suggestions are welcome.
CodePudding user response:
install vim and clone all the plugins to
/etc/vim/plugin
This wouldn't work, even on a physical machine.
Vim's runtime files are laid out in a specific way that is expected to be consistent at all levels so putting your files in random arbitrary locations won't do you any good because nothing will be where it is expected to be.
In this specific case, plugin/sonokai/autoload/airline/themes/sonokai.vim
is an autoloaded script but, because you naïvely put it under plugin/
, it is sourced as a global plugin, which can only create trouble.
Vim allows you to create directory hierarchies under plugin/
for organisational purpose but those subdirectories are for global plugins only. Filetype plugins, syntax scripts, indent scripts, autoloaded scripts, etc. have nothing to do there so they must be moved under the appropriate directory: ftplugin/
, syntax/
, etc.
That mechanism leads to a situation where, for a given third-party plugin foo
you would get files scattered around:
plugin/foo/foo.vim
syntax/foo/foo.vim
bar/bar.vim
indent/foo/foo.vim
bar/bar.vim
etc.
It works, technically, and it might even be usable if you don't have too many plugins, but it is inherently messy.
Nowadays, the preferred way to handle plugins is via the newish :help package
feature. Without spoiling the doc too much, there is a new directory in Vim's runtime called pack
under which you can put whole third-party plugins, each in their own directory, which is basically what you are trying and failing to do in plugin/
. So, instead of the layout above, you would have:
" one directory for plugin `foo`
pack/<whatever>/start/foo/plugin/foo.vim
indent/foo.vim
syntax/foo.vim
" and one directory for plugin `bar`
pack/<whatever>/start/bar/indent/bar.vim
syntax/bar.vim
In a normal setup for a normal user, that pack
directory should be created under $HOME/.vim/
. In this specific case, the right place is almost certainly $VIM/vimfiles/
. The exact value of $VIM
depends on many things so you will have to ask Vim where it is with:
:echo $VIM
and adjust your installation script accordingly.
I am not sure about the benefits of containerizing Vim, though.
CodePudding user response:
Since I was not able to comment, I'll leave these here. You can see how others do it in the most popular vim distribution SpaceVim.