How to configure on the .vimrc
file to use a particular set options for a particular filetype, but others for a different filetype?
For example, I want to enable expand tab (set tabs to be spaces) for Python files, but disable it for C++ files.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityI put this sort of thing in $HOME/.vim/ftdetect/{FILETYPE}.vim
. To accomplish what you want I would have the following files.
For python...
"$HOME/.vim/ftdetect/python.vim
autocmd BufRead,BufNewFile *.py set noexpandtab
And for C++...
"$HOME/.vim/ftdetect/cpp.vim
autocmd BufRead,BufNewFile *.cpp set expandtab
What these commands do is set the expandtab
or noexpandtab
options for a specific buffer which gets created for, or reads in, a file that matches one of the patterns *.py
or *.cpp
.
ftdetect
is meant for detecting filetypes, use an ftplugin
instead, there you don't need an autocmd
, just use setlocal
instead though.
Feb 9, 2015 at 15:00