0

I am trying to spread up some functions across files to make it a bit more manageable (and also to see how that works. So far I have three dummy variables/functions in one file:

# second.vim
let newer = "as"
let s:older = "by" " note: this variable will not be imported if source'd
func LogOutput1(msg, level=g:log_level_default)
    " ...
endfunc

# vimrc
source second.vim

As far as I'm able to understand, it seems that running the source will import all 'global' items from second.vim, so that it will import:

  • newer <-- yes, global variable
  • s:older <-- no, script-local
  • LogOutput1 <-- yes, 'global' (?) function

Is this accurate? What is the proper way to do imports, or is the above adequate?

2

Nowadays (since vim7), we don't need :source any more -- except for reloading plugins while maintaining them

Distribute your scripts within

  • {rtp}/plugin/ -- always loaded once after .vimrc
  • {rtp}/ftplugin/ -- always loaded once per buffer with a matching filetype
  • {rtp}/autoload/ -- lazily loaded, perfect for library plugin

Every thing is automatic. See this old Q/A on SU (that should be moved here if somebody knows how it's done)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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