When using vim, when I
vim test.php
Specify a file suffix name and it will be highlighted when writing code, but in many cases, vim is used directly when saving
:w test.php
to specify the file name.
Is there any way to make vim recognize the first line of the file? For example, if PHP writes `<?php
`, the code can be highlighted
If you want to use a script to automatically detect the first line to determine the file type, I think it is not easy to implement.
But it can be used:
(php, java, etc.) Call the highlighted syntax of C (php, java, etc.) language in this file.
Or use
(Abbreviation se ft=c) Modify the file type.
This can still be achieved and can be solved using autocmd, :au BufRead * switchFileTypeManully()
In fact, when you do this, you also need to judge the file type based on the file characteristics, just like the suffix name.
Just like the PE file, the system will judge the file based on the file header and file attributes