I just started working with Jekyll, which uses Liquid. As a templating language, Liquid is embedded into files of other types (e.g., HTML, CSS, or Markdown). Vim handles this sort of dual syntax highlighting admirably – when set filetype=liquid in, say, an HTML file, it preserves the HTML highlighting while additionally highlighting Liquid code.

But Liquid also has its own comment markers, which are distinct from HTML's, CSS's, and Markdown's. And when I want to comment something out in a .css.liquid file, more often than not, what I'm trying to do is make a /* CSS comment */, not a {{ comment }}Liquid comment{{ endcomment }}.

Unfortunately, I rely on tpope’s vim-commentary to comment stuff out, and that plugin relies on the filetype-specific commentstring setting to determine how to wrap comments.

So my question is, is there any way to enable Liquid syntax highlighting while keeping the native commentstring setting?

1 Answer 1


You can create file ~/.vim/after/ftplugin/liquid.vim containing:

if expand('%:e:e') == 'css.liquid'
    set commentstring=/*\ %s\ */

Which will change style of comments to /* ... */ only for Liquid files with .css.liquid extension.

  • I modified this to read =~ 'css', since Jekyll does away with the .liquid extension altogether. Would not have known about the after/ directory, though. Thanks!
    – Ryan Lue
    Nov 2, 2016 at 0:50

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.