Shibli
Shibli

Reputation: 6139

Invoke Makefile in different directory without exiting Vim

Referring to the structure below, suppose that I am in /test directory and I opened vim main.cpp. Running :make would invoke /test/Makefile. Now I do :edit ../src/foo.cpp and made changes here, too. I want to run make on /Makefile to create a shared library in /lib. How can I run make on /Makefile without exiting Vim?

project
|  Makefile
|+ lib
|+ include
|- src
    |  foo.cpp
|- test
    |  main.cpp
    |  Makefile

Upvotes: 6

Views: 1560

Answers (2)

Xavier Nicollet
Xavier Nicollet

Reputation: 353

You can also use:

 :lcd ..

Which will change the local directory (for the current window only). If you want to change the directory for all your windows, use:

:cd directory/

Then you can use :make as usual.

Upvotes: 0

dbosky
dbosky

Reputation: 1641

Just run:

:make -C path_to_dir_with_your_makefile

Where -C:

-C dir, --directory=dir
        Change to directory dir before reading the makefiles or doing anything else.  If multiple -C options are specified, each is interpreted relative to the previous one: -C / -C etc  is
        equivalent to -C /etc.  This is typically used with recursive invocations of make.

Upvotes: 8

Related Questions