In VIM, how can I mix syntax/ident rules of both jinja and javascript in the same file?

后端 未结 2 2075
挽巷
挽巷 2020-12-10 06:34

I\'m using jinja template language to generate html and javascript for a website. How can I make vim understand that everything between \'{{\'/\'}}\' and

2条回答
  •  甜味超标
    2020-12-10 07:17

    For the syntax, my SyntaxRange plugin makes the setup as simple as a single function call.

    For different filetype settings like indentation options, you have to install an :autocmd CursorMoved,CursorMovedI that checks into which region the current line falls (maybe using the syntax for hints, e.g. with synID()), and then swaps the option values depending on the result.

    Edit: For your particular use case, that would be something like:

    :call SyntaxRange#Include('{{', '}}', 'jinja')
    :call SyntaxRange#Include('{%', '%}', 'jinja')
    

    which you could put into ~/.vim/after/syntax/javascript.vim to apply it automatically to all JavaScript files.

提交回复
热议问题