Friday, March 25, 2016

Packages: best practices?

I would like to start using Vim's new package feature, but first I want to make
sure that I have understood how it is supposed to be used. Is it too early to
ask for tips about that?

First let me summarize what I have understood about packages (please correct
anything wrong):

- every package must be inside a directory called `pack` (`~/.vim/pack`).

- Each package should have (at least one of) two subdirectories: `start` and
`opt`.

- Plugins and ftplugins that must be available at launch time must go inside
`start`. What actually happens is that *any* directory under `start` is added
to `runtimepath` at startup independent of its content (much like Pathogen
does). Besides, if a directory contains a `plugin/foo.vim` file, that file is
sourced.

- Plugins and ftplugins that you want to be loaded lazily/manually go inside
`opt`. These may be loaded with `:packadd`. This is not exactly like loading
a plugin at startup, though, because if a plugin does something on VimEnter,
that something must be triggered manually.

- The `colorscheme` command searches both `pack/*/start` and `pack/*/opt/`
(beside `runtimepath`), so it does not matter where a colorscheme is.

If the above is accurate, I would give the following recommendations:

- Always put filetype plugins (no `plugin/foo.vim`) inside `start`. I see no
reason why you would want to do otherwise (unless you have a filetype
that you
seldom use and you really want to keep `runtimepath` as small as possible).
This type of plugin does not cause any file to be loaded at startup, unless
there is an `ftdetect/xyz.vim` file.

- Always put colorschemes inside `opt`. This avoid cluttering
`runtimepath`, and
they are found anyway.

For a concrete example of migration, let's say I am using Pathogen and I have
the following:

bundle/surround <-- regular plugin
bundle/youcompleteme <-- regular plugin
bundle/solarized <-- colorscheme
bundle/zenburn <-- colorscheme
bundle/ledger <-- filetype plugin
bundle/pgsql <-- filetype plugin
bundle/swift <-- filetype plugin

I might then move them to:

pack/bundle/start/surround
pack/bundle/start/ledger
pack/bundle/opt/youcompleteme
pack/languages/start/pgsql
pack/languages/start/swift
pack/themes/opt/solarized
pack/themes/opt/zenburn

Then, everything should work as before, with the exception of YCM, which must
now be loaded manually. To do so, I need

:packadd youcompleteme

but also

:call youcompleteme#Enable()

because :packadd does not trigger VimEnter.

Does what I said make sense? Am I missing something?

Nicola


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: