Makefiles can have commands such as:

BAR = $(subst ', '\'', $(FOO))

Here the first argument to subst is a single single quote resulting in for example:

FOO = some ' single ' quotes
BAR = $(subst ', '\'', $(FOO))
@echo "$(BAR)"

some '\'' single '\'' quotes

Same goes for single double quotes as well as things like:

BAR = $(subst ", \", $(FOO))
BAR = "$(subst ", \", $(FOO))"

The make.vim syntax file matches single quoted strings by:

syn region  makeSString start=+\(\\\)\@<!'+  skip=+\\.+  end=+'+  contains=makeIdent
  • /usr/share/vim/vim74/syntax/make.vim or the like.

But this does not match single standalone quotes, and the syntax comes out of sync and one get a mess on the lines following.

I am not fluent in syn commands. As a quick hack I have added the file .vim/after/syntax/make.vim with the contents:

syn region makeQarg start=#"\?\$(subst\s\+\(['"]\)\@=#hs=e+1 end=+['"]+
hi def link makeQarg Exception

(Use Error or the like for hi def link if you want to twiddle.)

This is not a fix. One issue is that the keyword subst and the leading $( also becomes a part of the match and thus one loose the syntax for that. Not a huge deal, but still.

Any suggestions on a fix?

  • You can "fix" the syntax with a comment: BAR = $(subst ', '\'', $(FOO)) # Fix Vim syntax: ' ... This is really just a workaround, but sometimes it's useful... – Martin Tournoij Nov 8 '15 at 7:11
  • @Carpetsmoker: Yes. Use that trick from time to time as well, but only if it is rare cases. – Runium Nov 8 '15 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.