开发者

Vim: multi-file editing - having different makes in different splits

I'm a recent vim convert (from fancy IDEs like eclipse.)

I love the :make command in vim and use it extensively; however I also like to edit multiple projects (with separate makefiles.)

So usually to edit more than one project I will do

pushd project1
vim project1.cpp
[suspend signal]
pushd ../project2
vim project2.cpp
开发者_JS百科

and now I can switch between the two projects with ctrl+z i.e. suspend signal, and fg.

When this becomes an issue is when I want to open one project in the context of another so I can do copy/pasting. So if instead in the above I do

pushd project1
vim project1.cpp
:vsp ../project2/project2.cpp

I can edit both concurrently in the same vim process, however I can't effectively build one or the other with the :make command, it will only build project 1.

Does anyone have some kind of scheme that gives them the best of both worlds: being able to edit concurrently while still being able to build multiple projects with the :make command all from the same vim process?


Are the make commands you want to execute the same for each? So the problem is just the current directory? You can use :lcd to change the directory only for the current window, so that it will run in the appropriate directory for each. To make this more automatic, you could set up an autocommand (on BufWinEnter, I think) for when you create that split window to run :lcd expand('%:h'), or just map a key to that if you don't want to always do it.

(You could also map a key/create a custom command for a combination of the lcd and make, probably saving keystrokes but then unnecessarily cd'ing before each make. Not that that takes long.)

P.S. The reason I asked if the make commands were the same is that you can actually set makeprg and other associated options locally (use :setlocal instead of :set).


vim's :make command really just executes the program configured as makeprg in the current directory (make by default).

By starting every vim process inside a project directory, you indirectly set the current directory for that vim session, but of course you can change the current directory inside a running session, e.g. when you started in project1/ you can simple cd to project2/ and build it inside vim with

:cd project2
:make

or like if you only what to change the directory for the current window, do what Jefromi suggests

:lcd project2
:make

There are plugins that say they makes this easier (this one seems to be popular), but I never needed to use them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜