Persistent :set syntax for a given filetype?

后端 未结 4 1080
失恋的感觉
失恋的感觉 2021-01-30 07:52

I\'m working on a Symfony2 project which uses Twig, and the filetypes are myfile.html.twig. Vim doesn\'t automatically detect the syntax highlighting and so applies

相关标签:
4条回答
  • 2021-01-30 08:21
    au BufNewFile,BufRead,BufReadPost *.twig set syntax=HTML
    

    And add this line to ~/.vimrc to make the settings persistent.

    0 讨论(0)
  • 2021-01-30 08:31

    I know this doesn't directly answer the question, however this answers the intent of the question, which is to get syntax highlighting working with Twig / Symfony 2

    I suggest you check out https://github.com/beyondwords/vim-twig (not mine), which provides:

    • the syntax highlighting file for *.html.twig,
    • file type detection for same, and
    • file type plugin, allowing you to modify various settings as required when editing *.html.twig files

    I hope this helps

    0 讨论(0)
  • 2021-01-30 08:39

    Add one of the following passages to your .vimrc:

    " Set the filetype based on the file's extension, overriding any
    " 'filetype' that has already been set
    au BufRead,BufNewFile *.html.twig set filetype=html
    

    or

    " Set the filetype based on the file's extension, but only if
    " 'filetype' has not already been set
    au BufRead,BufNewFile *.html.twig setfiletype html
    
    0 讨论(0)
  • 2021-01-30 08:42

    You can use autocmd to accomplish that, i.e.:

    augroup twig_ft
      au!
      autocmd BufNewFile,BufRead *.html.twig   set syntax=html
    augroup END
    

    Should work.

    0 讨论(0)
提交回复
热议问题