Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax support file |
Christian Brabandt | e978b45 | 2023-08-13 10:33:05 +0200 | [diff] [blame] | 2 | " Maintainer: The Vim Project <https://github.com/vim/vim> |
| 3 | " Last Change: 2023 Aug 10 |
| 4 | " Former Maintainer: Bram Moolenaar <Bram@vim.org> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5 | |
| 6 | " This file is used for ":syntax on". |
| 7 | " It installs the autocommands and starts highlighting for all buffers. |
| 8 | |
| 9 | if !has("syntax") |
| 10 | finish |
| 11 | endif |
| 12 | |
| 13 | " If Syntax highlighting appears to be on already, turn it off first, so that |
| 14 | " any leftovers are cleared. |
| 15 | if exists("syntax_on") || exists("syntax_manual") |
| 16 | so <sfile>:p:h/nosyntax.vim |
| 17 | endif |
| 18 | |
| 19 | " Load the Syntax autocommands and set the default methods for highlighting. |
| 20 | runtime syntax/synload.vim |
| 21 | |
| 22 | " Load the FileType autocommands if not done yet. |
| 23 | if exists("did_load_filetypes") |
| 24 | let s:did_ft = 1 |
| 25 | else |
| 26 | filetype on |
| 27 | let s:did_ft = 0 |
| 28 | endif |
| 29 | |
| 30 | " Set up the connection between FileType and Syntax autocommands. |
| 31 | " This makes the syntax automatically set when the file type is detected. |
Bram Moolenaar | 60895f3 | 2022-04-12 14:23:19 +0100 | [diff] [blame] | 32 | " Avoid an error when 'verbose' is set and <amatch> expansion fails. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 33 | augroup syntaxset |
Bram Moolenaar | 60895f3 | 2022-04-12 14:23:19 +0100 | [diff] [blame] | 34 | au! FileType * 0verbose exe "set syntax=" . expand("<amatch>") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 35 | augroup END |
| 36 | |
| 37 | |
| 38 | " Execute the syntax autocommands for the each buffer. |
| 39 | " If the filetype wasn't detected yet, do that now. |
| 40 | " Always do the syntaxset autocommands, for buffers where the 'filetype' |
| 41 | " already was set manually (e.g., help buffers). |
| 42 | doautoall syntaxset FileType |
| 43 | if !s:did_ft |
| 44 | doautoall filetypedetect BufRead |
| 45 | endif |