Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim filetype detecting

Tags:

vim

Can Vim detect filetype of a buffer with contents, but which doesn't have a name yet (not yet saved)? :filetype detect doesn't do much.

like image 240
Rook Avatar asked Jun 08 '12 19:06

Rook


2 Answers

Most filetypes are detected by their file name (and/or location), some (mostly those with a #! shebang line) by their contents.

If you don't want to save the buffer yet, but have detection, you can name the buffer via :file name.ext. Then, the detection via :filetype detect will work.

If you just want syntax highlighting (and corresponding filetype settings) quickly, just manually set the filetype via :setf name.

like image 72
Ingo Karkat Avatar answered Oct 20 '22 10:10

Ingo Karkat


You can do this manually.

:set filetype=EXT

Note that EXT is the extension for the filetype you want, not necessarily the name of the language itself.

like image 24
Nick McCurdy Avatar answered Oct 20 '22 08:10

Nick McCurdy