This question cannot be answered generally such that it applies to all text editors.
Vim recognizes files by suffix. This is driven by its default start-up scriptology, and you can hack up custom behaviors in your
For example, I wrote myself a C program called
autotab which looks at the contents of a file and determines the
expandtab settings for Vim based on how that file appears to be formatted.
When I load or reload a file in Vim, this program will analyze the contents, and then output the above Vim parameters which are interpolated into a
set command and executed. For example, if the file is found to be using a two space indentation, but evidently with a mixture of spaces and eight-space hard tabs, then the program will output
tabstop=8 shiftwidth=2 noexpandtab.
Exactly the same approach could be used to choose the syntax highlighting. Write a script that looks at some lines of a file, guesses the type, and then generates a
:set syntax ... command.
file utility could be used as the basis of the script. The program's "magic" database contains heuristics to detect some programming languages. Try running
file on various files of yours and see the output. You may be surprised at how well it identifies the content. So the strategy might be: run
file on the file, capture the output, analyze it into various cases and output the right Vim incantations. Then hook that into
GIT repo of