The reason Vim detects the filetype for *.cpp
and not for *.CPP
files is that Vim has auto-commands for *.cpp
setting the filetype, but nothing for *.CPP
:
:au BufRead *.cpp
--- Auto-Commands ---
filetypedetect BufRead
*.cpp if exists("cynlib_syntax_for_cpp")|setf cynlib|else|setf cpp|endif
:au BufRead *.java
--- Auto-Commands ---
filetypedetect BufRead
*.java setf java
:au BufRead *.CPP
--- Auto-Commands ---
What you need is a similar autocmd
for *.CPP
and *.JAVA
files:
au BufRead *.CPP setf cpp
au BufRead *.JAVA setf java
You can add these to your .vimrc
, or more appropriately from an organizational view, to a .vim
file in ~/.vim/ftdetect/
.
For .sh
files, Vim should already be detecting the filetype correctly, and the filetype would be sh
.
# vim: filetype=r
is a modeline:
There are two forms of modelines. The first form:
[text]{white}{vi:|vim:|ex:}[white]{options}
…
Examples:
vi:noai:sw=3 ts=6
vim: tw=77
The second form (this is compatible with some versions of Vi):
[text]{white}{vi:|vim:|Vim:|ex:}[white]se[t] {options}:[text]
…
Examples:
/* vim: set ai tw=75: */
/* Vim: set ai tw=75: */
If you absolutely must use a modeline, try something like the following after the shebang:
# vim: ft=sh
The filetypes are not necessarily the extensions. For example, .conf
files can have a filetype of apache
, .sh
files can have a filetype of zsh
if the shebang is #! /bin/zsh
, and so on. Open a file for which you know the filetype is correctly detected and run set ft?
:
:set ft?
filetype=apache
The default rules for setting the filetype are in $VIMRUNTIME/filetype.vim
:
vim +'e $VIMRUNTIME/filetype.vim'
Look for setf
in that file.