tags:

views:

175

answers:

1

Synopsis:

When calling vim's make command, it changes the current working directory (cwd) to the directory of the current file. It then runs the makeprg from there. I want to prevent the make command from changing the cwd, and instead call the makeprg from the directory of the parent vim instance

Example:

I have the following standard perl project hierarchy

    project/
      lib/
        My/
          Module/
            Foo.pm

My PERL5LIB is set to

    PERL5LIB=':lib'

In my .vimrc I have

    compiler perl
    set makeprg=perl\ -c\ %

I edit my module using vim from the root project level:

    /path/to/project$ vim lib/My/Module/Foo.pm

In vim :pwd works as expected:

    :pwd
    "/path/to/project"

Also calling !perl -c works as expected, finds my project lib, and displays the result in a shell window:

    :!perl-c %
    OUTPUT:
       perl -c lib/My/Module/Foo.pm
       lib/My/Module/Foo.pm Syntax ok

However :make returns an error

    :make
    "Can't open perl script lib/My/Module/Foo.pm : No such file or directory"

Setting makeprg to pwd shows the problem

    :set makeprg=pwd
    :make
    "/path/to/project/lib/My/Module"

So before make runs makeprg it is changing to the directory of the current file, which is why perl can't find 'lib/.../Foo.pm' there.

Is there any way to prevent make from doing this?

+3  A: 

If Vim's :make command is changing the current working directory, and autochdir is not set, a plugin may have added an autocommand to the QuickFixCmdPre set. One plugin that does this is eclim, which calls the QuickFixLocalChangeDirectory() function if g:EclimMakeLCD is set to 1.

Use :au to find all the autocommands in your current configuration, paying particular attention to entries for QuickFixCmdPre and make.

calid