我处理具有各种代码样式(制表符与空格等)的大型代码库。对于间距问题,我想根据文件的路径自动化一些vim设置。理想情况下,我想做类似的事情
if (absolute_path.match(".*/kernel")) then
use_tabs()
else if (abslute_path.match(".*/someuserspace_folder/*")) then
use_spaces()
end
谷歌搜索这个主题让我创造了这个科学怪人:
function! SetIndentSpaces()
set tabstop=4
set shiftwidth=4
set expandtab
echo "Using spaces for indentation"
endfunction
function! SetIndentTabs()
set tabstop=8
set shiftwidth=8
set noexpandtab
echo "Using tabs for indentation"
endfunction
autocmd BufEnter,BufRead */kernel/*.\(c|h\) call SetIndentTabs()
autocmd BufEnter,BufRead */userpace_code/*.\(cpp|c|h\) call SetIndentSpaces()
但是,我没有看到我的触发器被调用。我猜我的正则表达式是错误的,但我找不到任何方法来验证它(阅读:我很讨厌 vim)。
有人在我做错的事情中发现了一些明显的东西吗?