Skip to content

Instantly share code, notes, and snippets.

@joaopizani
Created May 28, 2012 02:48
Show Gist options
  • Save joaopizani/2816940 to your computer and use it in GitHub Desktop.
Save joaopizani/2816940 to your computer and use it in GitHub Desktop.
Parallel make in Vim with automatic detection of available processor cores
" set makeprg so that when you activate :make, then make -j<N+1> is
" run, where N is the exact number of processor cores in your machine.
function! SetMakeprg()
if !empty($NUMBER_OF_PROCESSORS)
let n = $NUMBER_OF_PROCESSORS + 0
elseif filereadable('/proc/cpuinfo')
let n = system('grep -c ^processor /proc/cpuinfo') + 0
else
let n = 1
endif
let &makeprg = 'make' . (n > 1 ? (' -j'.(n + 1)) : '')
endfunction
call SetMakeprg()
@joaopizani
Copy link
Author

If you know how to make this feature work also on Mac OS X then please fork this Gist and send me a pull request with your suggestions... It will probably involve using "sysctl", which I frankly know nothing about :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment