Ramashish Baranwal wrote:

Hi,

I would like to know how to define file specific settings (based on
file extension/type). I would prefer modifying my .vimrc file instead
of language specific .vim files. I am trying to achieve something
like-

if file-extension is .c or .cpp
   # expand tabs to spaces
   set sw=4 ts=4 expandtab
else if filetype is Makefile
   # don't expand tabs to spaces
   noexpandtab
endif

Any help would be appreciated. :)

Your example seems to indicate that you want to take actions based upon file specific settings, not how to define new ones.
The proper way to do this:

vim (home)/.vim/ftplugin/c.vim
 # expand tabs to spaces
 set sw=4 ts=4 expandtab
 :wq

vim (home)/.vim/ftplugin/make.vim
 # don't expand tabs to spaces
 noexpandtab
 :wq

Now, if you insist on doing something similar in your <.vimrc> instead of the "proper" way...

au FileType *.c,*.cpp,*.cxx,*.h,*.hpp set sw=4 ts=4 expandtab
au FileType makefile,Makefile set noexpandtab

All of this is untested, BTW.

Suggested reading:

 :help autocmd
 :help FileType
 :help ftplugin

Regards,
Chip Campbell

Reply via email to