I am working on linux kernel code sometimes, and I almost every time I forget to set :set noexptab
on vim when I am editing the kernel source code.
My default vimrc
expands tabs into spaces, but I would like to have a function that could distinguish if I am currently editing kernel source code or not, and set the expandtab
accordingly.
Basically, the kernel sources are in the linux-x.x.x directory, where is the root directory that I open the vim. I believe this is the start point.
There are a lot of Plugins and other methods to handle project specific settings. I would usually strongly support the plugin approach, since it does not cluster your vimrc
. But in your case that would mean to copy the project setting file to every new kernel folder. So in this case I would use following autocommand:
autocmd BufNewFile,BufRead /path/to/folder/linux-*/* set noexpandtab