Most file types are detected by their file name (and / or location), some (mainly those that have the #! Shebang string) by their contents.
If you do not want to save the buffer yet, but have detection, you can name the buffer through :file name.ext . Then detection through :filetype detect will work.
If you just want the syntax highlighting (and the corresponding file options) quickly, just set the file type for the file via :setf name .
source share