if filetype == tex
You have to manually detect the filetype first, because vim will detect it automatically only after sourcing your vimrc
.
Just add this:
`filetype detect`
before your code.
For those who want to check the current filetype and do something while editing, this should work:
if (&ft=='c' || &ft=='cpp')
:!g++ %
endif
You can use auto commands to achieve what you want:
autocmd BufNewFile,BufRead *.tex set spell
Another way is to use index()
:
let fts = ['c', 'cpp']
if index(fts, &filetype) == -1
" do stuff
endif
index()
searches for the first index of an element in a string, and returns -1
if not found. This way you can just append more filetype
values to your list, and not add more conditions for each file type.