如何高效地“制作” 与 Vim
我想做的似乎是一个非常基本的事情,但我找不到任何相关内容。 我正在像往常一样构建一个项目:
project
|-- bin
|-- inc
`-- src
我想使用 Vim 中包含的 make 命令来制作我的项目。 但每次我都必须指定 :make -C ../
。 我更喜欢,如果当前目录中没有 Makefile 文件,则进入父目录。 我已经在
set tags+=./tags;/
我的 .vimrc
中做到了这一点。
此外,默认情况下,该品牌是丑陋的。 是否有选项可以添加颜色,并允许直接访问错误(如在 Emacs 中)。
谢谢
What I am trying to do seems a very basic stuff, but I can't find anything about it. I am working on a project built as usual:
project
|-- bin
|-- inc
`-- src
I would like to make my project using the make command included in Vim. But each time I have to specify :make -C ../
. I would prefer, if there is not Makefile file in the current directory, go in the parent directory. I already do that with
set tags+=./tags;/
in my .vimrc
.
Furthermore, the make is by default ugly. Are there options to add color to make, and allow a direct access to the errors (as in Emacs).
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
稍微修改Adam所说的:
未转义,这
就是意思是,伪代码风格
这只向上一个目录。 如果您想要一个更通用的解决方案
根据需要添加尽可能多的目录,您需要能够搜索祖先目录,直到找到 Makefile,并且我不确定如何简单地从命令行执行此操作。 但是编写脚本(用您喜欢的任何语言)然后从 makeprg 调用它应该不难。
Slight modification of what Adam said:
Unescaped, this is
which means, pseudo code style
This only goes one directory up. If you'd like a more general solution that will go
as many directories up as necessary, you'll need to be able to search ancestor directories until a Makefile is found, and I'm not sure how to do that simply from the command line. But writing a script (in whatever language you prefer) and then calling it from your makeprg shouldn't be hard.
Rampion 的解是第一步,但根据 vim 负载计算。 当我加载多选项卡会话时,一个选项卡到另一个选项卡的路径可能不一致。
这是我的解决方案(+ tabnew 的额外内容)。
The solution of rampion is a first step, but computed on vim load. When I load a multi tab session, the path can be inconsistent from one tab to another.
Here my solution (+ extra with tabnew).
要回答第二个问题,您可以使用 VIM 中的 quickfix 功能来浏览错误。 Quickfix 将错误存储在缓冲区中,并允许您向前/向后导航它们。
您可能必须定义错误正则表达式以允许 VIM 从 Make 的输出中识别这些错误,但我似乎记得它开箱即用的效果相当好(我必须修改它对于 Java Ant 构建的工作方式 -显然不适用于这里)
To answer your second question, you can navigate through the errors using the quickfix functionality in VIM. Quickfix stores the errors in a buffer and allows you to navigate forward/backwards through them.
You may have to define the error regexp to allow VIM to identify these from Make's output, but I seem to remember that it works out-of-the-box rather well (I've had to modify how it works for Java Ant builds - obviously doesn't apply here)
到目前为止,最简单的解决方案是在 src 目录中有一个 Makefile,这是许多很多项目的设置方式,无论编辑器/IDE 是什么。 您仍然可以拥有一个调用
make -C src
的顶级 Makefile,其中在 src 中构建的规则位于它们所属的 src 中。By far the easiest solution is to have a Makefile in your src directory, which is the way that many, many projects are set up regardless of editor/IDE. You can still have a top-level Makefile that calls
make -C src
, with the rules for building in src located in src where they belong.如果项目根目录上只有一个 makefile,则可以使用另一种方法:
将项目路径设置为
b:projectDir
等变量,可以在开始执行之前使用“自动命令”更改到该目录:make
或:lmake
:Projectroot 插件 可用于设置
b:projectDir
; 它还提供了将当前目录更改为项目根目录的命令:Another approach can be used if you have a single makefile on project root directory:
With your project path in variable like
b:projectDir
it is possible to use an "autocommand" to change to that directory before start executing:make
or:lmake
:Projectroot plugin can be used to set
b:projectDir
; it also provides the commands to change the current directory to the project root directory:在 .vimrc 中设置 makecmd="make -C .."
set makecmd="make -C .." in your .vimrc