开发者

if filetype == tex

开发者 https://www.devze.com 2023-03-06 01:14 出处:网络
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?

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
0

精彩评论

暂无评论...
验证码 换一张
取 消