Vim:设置makeprg = xcodebuild的好方法?

时间:2009-12-04 12:39:13

标签: vim command-line xcodebuild

在vim中设置makeprg=xcodebuild的最佳方式是什么?

我在文件中使用filetype行来指示文件是objective-c(而不是matlab或cpp),方法是将文件的第一行设置为:

/* vim: set filetype=objc : */

在vimrc中有这个:

set modelines=1

我可能希望使用:mak在当前目录中运行此命令:

xcodebuild -activetarget -activeconfiguration

我通常最终手动设置xcodebuildmakeprg,以便我可以:mak进行编译。

我总是在项目根目录中,我有.xcodeproj个文件,所以我不必担心搜索项目文件。

设置makeprg的最佳方法是什么? FtpluginCompiler插件?

任何想法都赞赏。

2 个答案:

答案 0 :(得分:1)

我会说ftplugin,这很容易。在.vim/ftplugin/objc.vim

中写下此内容
set makeprg=xcodebuild\ -activetarget\ -activeconfiguration

此外,如果Vm的文件类型检测器在前十行中注意到#include#import/*,则会将其视为Objective-C。您可以编写ftdetect插件来更改默认值:.vim/ftdetect/objc.vim

autocmd BufNewFile,BufReadPost *.m set filetype=objc

答案 1 :(得分:1)

您可以将以下内容放入.vimrc:

if len(glob( getcwd() . '/*.xcodeproj' )) > 0
    let &makeprg = 'xcodebuild'
endif

因此,当你启动vim并且当前目录中有一个* .xcodeproj时,它会将makeprg设置为xcodebuild。