Search code examples
variablesvimdefaultvim-plugin

vim: where to put default values for plugin variables?


What is the best way to set default values for plugin variables?

Ideally, I would like to have those variables set before .vimrc is loaded, such that the user can override these values if he wants to. Is that possible?


Solution

  • Are you writing a plugin?

    Your plugin will likely be executed after your user's ~/.vimrc: you can't do anything before that.

    You could just forget about doing anything prior to the execution of ~/.vimrc and use conditionals in your script:

    if !exists("g:pluginname_optionname")
      let g:pluginname_optionname = default_value
    endif
    

    Or you could use an autoload script (:h autoload) and ask your users to put something like the following in their ~/.vimrc before any customization:

    call file_name#function_name()
    

    with that function doing all the initialization stuff.