1

I'm trying to write a custom command in Vim to make setting the makeprg variable for an out-of-source build easier. Having read the command manual, so far I've got as far as this

command! -complete=file -nargs=1 Cmakeprg call set makeprg=cmake --build <args><CR>

but it isn't working. How do I call "set" within the command?

0

2 Answers 2

3

You :call functions, :set is an Ex command just like :call (as it's invoked with the : prefix).

A complication with :set is that whitespace must be escaped with \, but that can be avoided by using :let with the &option, and <q-args> automatically quotes the passed command arguments.

You also don't need <CR>; this isn't a mapping. Taken all together:

command! -complete=file -nargs=1 Cmakeprg let &makeprg = 'cmake --build ' . <q-args>
Sign up to request clarification or add additional context in comments.

Comments

0

Add a colon in front of "set" and use a <CR> to execute it: :set … <CR>

Do not use call.

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.