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 .vimrc
.
For example, I wrote myself a C program called autotab
which looks at the contents of a file and determines the shiftwidth
and tabstop
and 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.
The 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 .vimrc
.
GIT repo of autotab
: http://www.kylheku.com/cgit/c-snippets/tree/autotab.c
file(1)
.nano
andgedit
on all language files, whether they have an extension or not. Arch64_bit/Gnome 3. I'd say it's something specific to your particular setup, unless you provide more details.