0

After using vim for some time now, my ~/.vim/ beginning with my first experiments with vim got really messy over time. So I thought, it would be time to tidy up and to begin with a plugin manager with a clean configuration.

Since I share my configuration over multiple machines, I usually manage my ~/.vim/ path with a git repo. To avoid a big .vimrc, I put my own configuration under ~/.vim/plugin/. This allowed me, to keep all my shared configuration in this folder and to use ~/.vimrc only for machine dependent configuration.

Starting with VAM over NeoBundle and now Vundle I have always the same problem. If I add the required configuration under ~/.vim/plugin/pluginmanager.vim instead of ~/.vimrc, the installed plugins do not load or were only partially loaded. The command :echo &rtp lists the correct bundles, but :scriptnames does not include the installed plugins. If I execute mv ~/.vim/plugin/pluginmanager.vim ~/.vimrc everythings works as expected.

Can anyone explain this behavior and perhaps offer a solution?

My pluginmanager.vim looks like this:

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
Plugin 'bling/vim-airline'
Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'tomtom/tlib_vim'
Plugin 'garbas/vim-snipmate'
Plugin 'honza/vim-snippets'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

My vim installation is version 7.4.52

Trendfischer
  • 7,112
  • 5
  • 40
  • 51

2 Answers2

1

I would recommend using the ~/.vimrc file for general configuration and having another file such as ~/.vimrc.local with your machine specific configuration. You can source ~/.vimrc.local by adding the following to your ~/.vimrc.

if filereadable(glob("~/.vimrc.local")) 
    source ~/.vimrc.local
endif

Credit: http://blog.sanctum.geek.nz/local-vimrc-files/


To solve your issue try adding runtime! bundle/**/*.vim to the end of your pluginmanager.vim file.

See also: :help init

Brett Y
  • 7,171
  • 1
  • 28
  • 42
  • Thanks for the answer. Sourcing other files is a nice way and a legitimate solution. But my intention is to avoid .vimrc. Without a plugin manager I did not missed it and my different configurations are better organized in the plugin directory. But it may be some sort of individual preference. – Trendfischer Mar 17 '15 at 22:06
  • @Trendfischer: Just symlink `~/.vimrc` to something in your Git repo. – Kevin Mar 18 '15 at 02:57
1

The problem is in the startup order. After your ~/.vimrc has been executed (as the first thing during startup), Vim executes something like :runtime! plugin/*.vim to load the plugins. As your plugin manager is only then invoked, the changes in the 'runtimepath' do not reach that triggering :runtime command any more, and the plugins fail to load.

There are many workarounds:

  • Move your script to ~/.vim/pluginmanager.vim and explicitly :runtime pluginmanager.vim it from (each copy of) your ~/.vimrc.
  • Re-trigger via :runtime! plugin/*.vim.

But I agree with @brettanomyces that the best solution would be to use ~/.vimrc as intended, and place system-specific configuration into a different script instead.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Yes, that explains the behavior. Thanks for the insight. But as solution, I will use the `~/.vim/vimrc` like @FDinoff suggested in his comment. That is compatible with the version control system approach. – Trendfischer Mar 18 '15 at 14:58
  • 1
    Yes, that's a good solution, provided you have current Vim versions on all systems, as this is a fairly recent feature. – Ingo Karkat Mar 18 '15 at 18:48
  • Ah, good point. I tested the versions. The `:version` command was helpful, it lists, wich vimrc files are used. – Trendfischer Mar 19 '15 at 09:38