I'd like to make it so that in my current project, when I write the file :w, if the file is *.cpp then also automatically run the substitution
:%s@^\( \)\+@\=repeat("\t", strlen(submatch(0)) / &ts)
To replace spaces with tabs.
I want it to affect only my current directory/project.
So I thought about using set exrc and adding an autocmd
autocmd BufWrite *.cpp :%s@^\( \)\+@\=repeat("\t", strlen(submatch(0)) / &ts)
but set exrc should be used with set secure and set secure disables autocmd.
Is there another solution where I won't have to disable set secure?
.exrcapplies to subdirectories as well. But, honestly, I'd use editorconfig for that purpose. BTW, why don't you use:setlocal noexpandtab+:retab? – Luc Hermitte Mar 18 '21 at 14:23:setlocal noexpandtab– minseong Mar 18 '21 at 14:27