0

Installing plugins through vim-plug involves putting the following code inside the vimrc file.

call plug#begin('~/.vim/plugged')

Plug 'user/repository'

call plug#end()

I install a lot of plugins, and I don't want to put all the code inside the main configuration file. I'd instead like to source it from a separate file dedicated to plugins.

I name that file as Plugins.vim and source it inside the main vimrc file putting the following in the first line.

source $HOME/.vim/Plugins.vim

Unfortunately, the plugins don't get loaded, and even though Vim reads the file, it outputs error messages relating to that line where it is being asked to source.

I tried to fix it by changing the path and file permissions but with no results.

Note: The vimrc file may be located inside the home directory as .vimrc or in .vim directory as vimrc.

The error is:

E471: Argument required

It is either related to source or the file itself (I set file's permission to 777, but I remember sometimes it did not open the file and issued file is unreadable error as well.)

Currently, I am using one file the .vimrc as sourcing doesn't work for me.

6
  • 2
    What are the error messages?
    – Herb
    Jan 21, 2017 at 20:26
  • Maybe not a duplicate but strongly related: How to load plugins from my vimrc and from another file?. I think adding the test with filereadable() could help you.
    – statox
    Jan 23, 2017 at 7:50
  • I've updated my post and added the error.
    – user10767
    Jan 23, 2017 at 12:45
  • Why the file should be unreadable? Or is it the quotes for source '' "", should I pass a variable and not a quoted path string to source?
    – user10767
    Jan 23, 2017 at 12:46
  • 2
    @Chinggiss6 Where do you have quotes? Note, " in your vimrc usually denotes the start of a comment, so this would explain why your :source command does not see an argument! Apr 19, 2017 at 16:21

3 Answers 3

1

I would go with either

" load Plugins.vim, searching it in "all vim places"
runtime Plugins.vim

or

" load Plugins.vim from the relative path of your vimrc
source <sfile>:h/.vim/Plugins.vim
0

I think, you have to call call plug#begin('~/.vim/plugged'), only then you can source the plugin file. It is good practice to have the plugins in a separate file btw!

3
  • 1
    No, it should work with a simple :source Apr 19, 2017 at 16:22
  • 1
    @ChristianBrabandt: I agree with you, but he clearly states, that he sources the plugin file in the first line of vimrc, only later does he call plug. That is the problem, the examples for plug clearly state: first call plugged, then source any plugins.
    – mike
    Apr 19, 2017 at 19:03
  • 1
    he said he put the complete plug section into a new file. That should work. However, as I have commented, I believe the problem is actually that he quoted the file (as he stated in a comment later, but not in the example he showed) Apr 19, 2017 at 19:12
0

Inside my vimrc I have a line that loads my plugins like this

source ~/.vim/rc/bundles.vim

Then inside my bundles.vim I do the following:

call plug#begin('~/.vim/bundle')
  Plug 'foo/vim-someplugin'
  source ~/.vim/rc/plugins/someplugin.vim
call plug#end()

if you don't want to use hard coded paths I recommend something like this

execute 'source' fnamemodify(expand('<sfile>'), ':h') . '/path/to/file.vim'

or

source <sfile>:h/.vim/Plugins.vim

as Maxim pointed out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.