Question

What is the best way to set makeprg=xcodebuild in vim?

I'm using filetype line in files to indicate that the file is objective-c (as opposed to matlab or cpp) by setting up the first line of my file to:

/* vim: set filetype=objc : */

and having this in vimrc:

set modelines=1

I would probably want to use :mak to run this command in the current directory:

xcodebuild -activetarget -activeconfiguration

I usually end up setting manually xcodebuild as makeprg so that I can do :mak to compile.

I'm always in the project root directory where I have .xcodeproj files so I don't have to worry about searching for project files.

What's the best way to setup makeprg? Ftplugin? Compiler plugin?

Any ideas appreciated.

Was it helpful?

Solution

I'd say ftplugin, it's very easy. Write this in .vim/ftplugin/objc.vim:

set makeprg=xcodebuild\ -activetarget\ -activeconfiguration

Also, Vim's filetype detector will consider your .m file to be Objective-C if it notices #include, #import, or /* in the first ten lines. You can write an ftdetect plugin to change the default: .vim/ftdetect/objc.vim:

autocmd BufNewFile,BufReadPost *.m set filetype=objc

OTHER TIPS

You could put something like the following into your .vimrc:

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

So when you start vim and there is a *.xcodeproj in the current directory, it sets the makeprg to xcodebuild.

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