Find what filetype is loaded in vim
&filetype
for script usage
Minimal example:
echo &filetype
More realistic usage example:
if &filetype ==# 'c' || &filetype ==# 'cpp'
setlocal noexpandtab
endif
&
syntax works for all options: https://vi.stackexchange.com/questions/2569/how-do-i-check-the-value-of-a-vim-option-in-vimscript
You can also add the filetype to your status line or window title using the %y
and %Y
items. See
:help 'statusline'
:help 'titlestring'
When I wanted to find the filetype it was because I was having the .ipy extension modifying an ipython script. The above Q&A worked great to see that the ipython extension was not being treated as python (somewhat obvious). Thus I wanted to force set the filetype, and I found this from the ever helfpul vim site. http://vim.wikia.com/wiki/Forcing_Syntax_Coloring_for_files_with_odd_extensions
Adding the below to your .vimrc works
au BufRead,BufNewFile *.ipy set filetype=python
:set filetype?