0

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.

1
  • <bang>0 means either !0 which is 1 or 0 which check the presence of a bang (i.e Umake or Umake!) Commented Feb 18, 2017 at 4:40

1 Answer 1

1

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...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.