I am pretty new to emacs so please excuse the rookie question.

So I am editing a helm chart template, and have enabled yaml-mode since most of helm uses yaml.

but I wanted to add some highlighting to the helm specific parts.

so for example

  name: {{.name}}

I wanted {{.name}} to be highlighted which was easy enough

(add-hook 'yaml-mode-hook '(lambda ()
  (highlight-regexp "{{[^-].*?}}" font-lock-constant-face)

but I am having issues with the if statements. for example

{{- if .configMap }}
apiVersion: v1
kind: ConfigMap

I want the if part to be highlighted, but nothing else. in other words, highlight if, don't highlight .configMap

I thought it should be possible with a positive lookbehind, but sounded like that is not possible with an Emacs Lisp regexp.

How can I highlight only the if part?

1 Answer 1


I think (regexp-opt '("if") 'words) will generate a regexp that does what you want.

(Node Regexp Functions of the Emacs manual documents functions that help you generate regexps.)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.