Reputation: 8047
I wish when I edit some source file under a directory, press will trigger cmake and make build, like below:
command -bang -nargs=? Umake call Myfunction(<bang>0)
function! Myfunction(forced)
lcd %:p:h
call system('cmake && make')
endfunction
nmap <F5> :Umake<cr>
This code snippet is copied from internet and did a bit modification, not very sure if it's totally OK. After re-enter vim, Press , the left-bottom command windows shows ":Su" and nothing happened.
(1) Why nothing happened, any syntax issue in Myfunction? (2) Is the line "command -bang" necessary? What's the meaning of 0 here?
Thanks.
Upvotes: 0
Views: 52
Reputation: 32926
You don't want to compile with system()
Set instead :let &makeprg = 'cd "compilation/dir" && make $*'
. Then :make target -j 12
.
Again, build-tool-wrappers plugin already handles out-of-source tree compilation (with multiple compilation directories), target detection, background compilation...
Upvotes: 1