vim: persistent:ustawia składnię dla danego typu pliku?

Pracuję nad projektem Symfony2, który używa Twig, a typy plików to myfile.html.twig. Vim nie wykrywa automatycznie podświetlania składni, więc nie stosuje żadnego. Mogę użyć :set syntax=HTML po otwarciu pliku, ale to jest ból podczas przeskakiwania między plikami.

Czy istnieje sposób na stałe ustawianie podświetlania składni dla określonego typu pliku w Vimie?

4 answers

Możesz użyć autocmd aby to osiągnąć, tzn.:

augroup twig_ft
  au!
  autocmd BufNewFile,BufRead *.html.twig   set syntax=html
augroup END
Powinno zadziałać.
 84
Author: Hauleth,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-05-24 10:10:34

Dodaj do swojego .vimrc jeden z następujących fragmentów:

" 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

Lub

" 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
 24
Author: Muhammad Reda,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-26 17:15:11
au BufNewFile,BufRead,BufReadPost *.twig set syntax=HTML

I dodać tę linię do ~/.vimrc, Aby ustawienia stały się trwałe.

 6
Author: Igor Chubin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-07-26 09:33:20

Wiem, że to nie odpowiada bezpośrednio na pytanie, ale odpowiada na intencję pytania, którym jest podświetlanie składni działające z gałązką / Symfony 2

Proponuję sprawdzić https://github.com/beyondwords/vim-twig (nie mój), który zapewnia:

  • Plik podświetlania składni *.html.gałązka,
  • wykrywanie typu pliku dla tego samego i
  • wtyczka typu pliku, pozwalająca na modyfikację różnych ustawień w zależności od potrzeb podczas edycji*.html.gałązka pliki

Mam nadzieję, że to pomoże

 1
Author: ebonhand,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-08-27 14:27:39