I am on WSL trying to understand why my fakeclip.vim doesn't work.

I've added

let g:fakeclip_platform = s:PLATFORM

into ~/.vim/bundle/vim-fakeclip/autoload/fakeclip.vim, but I can't access the variable I have created. However I can access g:fakeclip_terminal_multiplexer_type.

So I was suspecting vim to not load/use this file. Fakeclip is organized as follow:

├── autoload
│   └── fakeclip.vim
├── doc
│   ├── fakeclip.txt
│   └── tags
├── Gemfile
├── plugin
│   └── fakeclip.vim

So I executed this:

$ echo "let g:foo=42" >> .vim/bundle/vim-fakeclip/plugin/fakeclip.vim
$ echo "let g:bar=42" >> .vim/bundle/vim-fakeclip/autoload/fakeclip.vim

But once again, g:bar doesn't exist. So I removed the autoload file:

$ rm .vim/bundle/vim-fakeclip/autoload/fakeclip.vim

But g:fakeclip_terminal_multiplexer_type which is only defined in this file is still available.

Of course between each attempt I quit and restarted vim. I also removed .viminfo just in case.

Could some explain what's happening here?

1 Answer 1


autoload plugins are sourced:

  • either when we source them explicitly (like in :runtime autoload/fakeclip.vim)
  • or when we call a function that starts in foo#bar#whatever(), it'll source autoload/foo/bar.vim, even if the function doesn't exist.

So, if you want to define a variable in an autoload plugin,

  • either use a dedicated interface: :call fakeclip#_init() which is quite cumbersome and defeats the purpose of using autoload plugins;
  • or set the variable in a plain plugin/ instead;
  • or don't even try to set it if you're just trying to access an option, you could instead provide an internal accessor for your option, and use this accessor instead of g:fakeclip_platform from your code.

    function! fakeclip#_platform()
        return get(g:, 'fakeclip_platform', somedefaultvalue)

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.