I want to run a c开发者_开发百科ommand in the .vimrc in case a file is a latex file. I think I have something with the syntax, it does not work. Any clue?
if &filetype=='tex'
set spell
endif
You can use auto commands to achieve what you want:
autocmd BufNewFile,BufRead *.tex set spell
For those who want to check the current filetype and do something while editing, this should work:
if (&ft=='c' || &ft=='cpp')
:!g++ %
endif
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.
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.
just to add to above using index. A quick block to check filetypes using ft
update :
if index(['tex'], &filetype) != -1
echom "this is latex filetype!"
endif
精彩评论