Created
May 28, 2012 02:48
-
-
Save joaopizani/2816940 to your computer and use it in GitHub Desktop.
Parallel make in Vim with automatic detection of available processor cores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :)