Why isn’t the scripts in the autoload folder being executed in Vim


I'm trying to use Pathogen to manage my Vim extensions. My bundle folder looks like this:

├── vim-pathogen
│   └── autoload
│       └── pathogen.vim
└── vim-smoothscroll
    └── autoload
        └── smooth_scroll.vim

And my vimrc file includes this:

let s:root = fnamemodify(resolve(expand(":p")), ":h")

" Initiate pathogen.
exec "source " . s:root . "/vimfiles/bundle/vim-pathogen/autoload/pathogen.vim"
exec pathogen#infect()

My vimrc file is a symlink located in ~ but pointing to a folder inside my Dropbox folder.

This appears to work when I start Vim. Pathogen has added vim-smoothscroll to my runtimepath:

:set runtimepath?

The problem is that the script smooth_scroll.vim hasn't been loaded:

  1: ~/.vimrc
  2: ~/Dropbox/Personal/config_sync/vim/vimfiles/bundle/vim-pathogen/autoload/pathogen.vim
  3: ~/vim/share/vim/vim74/syntax/syntax.vim
  4: ~/vim/share/vim/vim74/syntax/synload.vim
  5: ~/vim/share/vim/vim74/syntax/syncolor.vim
  6: ~/vim/share/vim/vim74/filetype.vim
  7: ~/vim/share/vim/vim74/menu.vim
  8: ~/vim/share/vim/vim74/autoload/paste.vim
  9: ~/Dropbox/Personal/config_sync/vim/vimfiles/colors/codeschool.vim
 10: ~/Dropbox/Personal/config_sync/vim/_vimrc_gui
 11: ~/Dropbox/Personal/config_sync/vim/_vimrc_keybinds
 12: ~/vim/share/vim/vim74/plugin/getscriptPlugin.vim
 13: ~/vim/share/vim/vim74/plugin/gzip.vim
 14: ~/vim/share/vim/vim74/plugin/matchparen.vim
 15: ~/vim/share/vim/vim74/plugin/netrwPlugin.vim
 16: ~/vim/share/vim/vim74/plugin/rrhelper.vim
 17: ~/vim/share/vim/vim74/plugin/spellfile.vim
 18: ~/vim/share/vim/vim74/plugin/tarPlugin.vim
 19: ~/vim/share/vim/vim74/plugin/tohtml.vim
 20: ~/vim/share/vim/vim74/plugin/vimballPlugin.vim
 21: ~/vim/share/vim/vim74/plugin/zipPlugin.vim
 22: ~/vim/share/vim/vim74/syntax/ruby.vim
 23: ~/vim/share/vim/vim74/syntax/vim.vim
 24: ~/vim/share/vim/vim74/syntax/python.vim

Why is that? Loading the script manually works fine.

Best Answer

You are doing crazy things with your setup. Did you find the default way too easy and solid?

  • Vim's runtime files, everything under /share/vim/vim74, should be in /usr/share/vim/vim74. Did you install Vim in your $HOME because of privilege issues?

  • All your personal stuff (colorschemes, plugins, syntax scripts...) must go into ~/.vim. That directory can be a symlink to that vimfiles directory in your Dropbox which would remove the "need" for all your hacks. Assuming you are on Linux, just do:

    ln -s /home/username/Dropbox/Personal/config_sync/vim/vimfiles /home/username/.vim
  • pathogen.vim is not supposed to be sourced like that. It's in the autoload directory precisely because the autoload mechanism prevents it to be sourced in order to save time at startup.

    Additionally, pathogen.vim should be in ~/.vim/autoload/.

    With a "normal" setup, or a symlink that makes it look "normal" to Vim, there's no need to go through all those hoops.

  • smooth_scroll.vim should not be in an autoload directory, it comes in a plugin directory, why did you change that? That's why the plugin doesn't work.

  • Did you know that 7.4 now looks both for ~/.vimrc and for ~/.vim/vimrc? It makes it a lot easier to manage your config by keeping everything in a single directory.

Step 1: change the structure of that vimfiles directory in your dropbox to look like this:

  |   +-pathogen.vim

Step 2: move your vimrc inside the vimfiles directory in your dropbox.

step 3: remove all the useless path-related stuff in that file. The pathogen-related part should look like this:

execute pathogen#infect()
execute pathogen#helptags()

step 4: remove your ~/.vimrc:

$ cd
$ unlink .vimrc

step 5: create a symlink to your dropbox-synced directory:

$ ln -s /home/username/Dropbox/Personal/config_sync/vim/vimfiles /home/username/.vim