设置“makeprg”;通过 Vim 中的模型行
默认情况下,makeprg
设置为 make
。但是,我有很多项目,不同的构建配置和目标驻留在同一目录中。
这当然需要我在调用 make
时指定一个目标。
例如,我有一个项目,它设置为通过调用 make foo
来构建源文件
,并且该项目包含许多此类源文件。
当我在 Vim 中编辑
时,如何才能实现这一点,makeprg
设置为 make
我想到了每个文件中的模型行,但是通过模型行设置
makeprg
是被禁止的(出于安全考虑?)。
请注意,此设置仅适用于某些项目,因此我不想修改 make
的一般值 - 否则我只是
set makeprg=make\ expand("%:t:r")
(或类似的东西)我的.gvimrc
。
By default, makeprg
is set to just make
. However, I’ve got a lot of projects where different build configurations and targets reside in the same directory.
This of course necessitates that I specify a target when invoking make
.
For example, I’ve got a project that’s set up to build a source file <foo>.cpp
by invoking make foo
, and the project contains a number of such source files.
How can I achieve that when I’m editing said <foo>.cpp
in Vim, makeprg
is set to make <foo>
? I thought of modelines in each file, but setting makeprg
via the modeline is forbidden (due to security concerns?).
Notice that this setting is only appropriate for some projects so I don’t want to modify the general value of make
– otherwise I’d just
set makeprg=make\ expand("%:t:r")
(or something like that) in my .gvimrc
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我正在使用插件 我的,可以启用特定于项目的设置来调整此类内容。
这样我的
.vimrc
就不会被项目特定的东西弄乱了。相反,在每个项目根目录中,我都有一个包含我的各种设置的_vimrc_local.vim
文件。另一种解决方案是将
:make
调用封装到另一个命令或映射中,然后使用可以使用另一个插件设置的变量调用:make
: let-modeline。PS:
.gvimrc
旨在包含特定于 vim 图形版本的内容。通过将设置放入.gvimrc
中,普通 vim 将不会被配置。I'm using a plugin of mine that enables project-specific settings to tune that kind of things.
This way my
.vimrc
is not cluttered with project-specific things. Instead, in each project root directory I have a_vimrc_local.vim
file that contains my various settings.Another solution would be to encapsulate
:make
call into a another command or a mapping that in turn calls:make
with a variable that you could set with another plugin: let-modeline.PS: the
.gvimrc
is meant to contain things specific to the graphical version of vim. By putting your settings into your.gvimrc
, plain vim won't be configured.您应该能够映射
:make %<
我相信它会做您想要的You should be able to map
:make %<
which I believe will do what you want如果您可以不通过模型行而是通过它们的文件夹来区分您的项目,那么应该可以与自动命令类似。以下是
:help autocmd-patterns
中的示例与您的示例代码的组合。(请注意,我还没有测试这个确切的命令,而是有一些自动命令用于根据我的 vimrc 中的文件类型设置 makeprg)
It should be possible to something similar with autocommands, if you can distinguish your project not by modeline but by their folder. The following is a combination of an example from
:help autocmd-patterns
and your example code.(Note that I haven't tested this exact command, instead I have some autocommands for setting makeprg depending on the filetype in my vimrc)