Question

Usually when I call :make vim builds the Makefile it finds in the folder where I open the session. That doesn' mean that I am interested in building that particular makefile.

Suppose I have 2 open files/tabs and these files are in 2 separate folders. None of those folders are the one I started the session; each of these 2 folder do have a Makefile in it.

Is there a way to tell vim to build the Makefile it finds in the same folder of the tab I am looking now? So essentially I switch to a tab and :make compiles the Makefile found in that folder.

The reason for this is that I mapped CTRL-B to build the makefile and that is handy ,but when I have different open projects each depending on each other that doesn't work anymore as I have to build every single project. I would like to avoid having 2 separate instances of vim.

Was it helpful?

Solution

You can use the :lcd command in each tab to change the working directory. If you do this as long as the tab page contains a single window, any future split buffers will inherit the (window-local) setting, and you effectively have tab-local working directories.

Alternatively, :set autochdir will always switch the working directory to the current buffer's. As long as you have flat projects (where the Makefile is in the same directory as the sources you're editing), that would be a solution, too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top