I have a plugin (a unite sub-module) that filters extremely large textfiles down to generate a helpful 'table of contents'. I would like to provide the user with the ability to enable/disable many of the filters... and I would like that setting to persist through each vim invocation. (instant updates across concurrent sessions is not necessarily needed)

Is there a mechanism for doing this built into vim? Or do I need to create and manage a "dot file" in the user's $HOME? Or is there an accepted standard way of handling this?

EDIT: I can't really just let the user set a global variable in the vimrc, because the list of options is currently several hundred entries long, and the current interface is simply "type d with the index open" to remove from the list.

  • I'm aware that for user-variables, you can ensure that viminfo includes !, and then certain types of g:variables will be stored persistently in the viminfo file, but it's not reasonable for most plugins to modify viminfo on users.
    – jkerian
    Sep 29, 2016 at 18:50
  • I'm not extremely knowledgeable on this subject, but I think that all the plugins I've used just defined g:boolVariable and then directed the user to set it in his own vimrc. Then you can just check the options the user has set and work from there.
    – Tumbler41
    Sep 29, 2016 at 18:59

1 Answer 1


One way to do it is to have your plugin define a global variable storing the path to that specific "persistent settings/enabled filters" file. This is similar to how various plugins that have to 'cache' some values work. So, the documentation could look like this:

g:myplugin_enabled_filters_path     *g:myplugin_enabled_filters_path*
    This variable points to the file that stores enabled filters for
    <myplugin> etc.

    Default value is "$HOME/.myplugin.filters"

You can use the $HOME variable to build a default value for this path, and store your enabled filters there. The users can change the path by changing the above variable in their vimrc. I assume you intend to offer some means (functions, commands, key maps) to conveniently enable/disable various filters on the fly, while using your plugin (filters which you remember in that file), so that the user doesn't have to deal with them directly. Otherwise, it's simpler to let the user modify a global variable that stores a list/dict etc. of enabled filters (that can "persist" by having the variable saved in vimrc) and read that instead (as per Tumbler41's comment above).

For more details, you can follow how g:neocomplcache_temporary_dir is defined and used in Shougo's neocomplcache.vim plugin.

Also, you can easily serialize (save/restore) any vim variable (even a dictionary) in that file by using something like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.