我每天都使用几种不同的编程语言,我希望每种语言都有不同的标签宽度(空格).例如:我使用
Ruby的“标准”2空格,但我们现有的所有Matlab代码都使用4个空格.
我的个人〜/ .vimrc有这个:
augroup lang_perl au! set tabstop=4 " tabstop length N in spaces set shiftwidth=4 " make >> and friends (<<,^T,^D) shift N,not the default 8 set expandtab " Use spaces instead of tabs augroup END augroup lang_ruby au! set tabstop=2 " tabstop length N in spaces set shiftwidth=2 " make >> and friends (<<,not the default 8 set expandtab " Use spaces instead of tabs augroup END
这些工作,但以下不是:
augroup lang_matlab au! set tabstop=4 " tabstop length N in spaces set shiftwidth=4 " make >> and friends (<<,not the default 8 set expandtab " Use spaces instead of tabs augroup END
我真的不明白augroup lang_ruby是如何计算出我正在编辑Ruby文件的. (我的搜索提出了ftdetect,但解决方案并不明显.)似乎vim不知道我正在使用augroup lang_matlab编辑Matlab.我做了什么改变才能使这项工作?
解决方法
如果你想为{filetype}设置大量的设置,你应该将它们放入〜/ .vim / ftplugin / {filetype} .vim或与〜/ .vim / ftplugin / {filetype} / **相匹配的文件中/*.vim(例如:〜/ .vim / ftplugin / ruby / foo.vim,〜/ .vim / ftplugin / ruby / foo / bar.vim).在这种情况下,您根本不需要任何自动命令.如果您仍想使用自动命令,请使用以下命令:
augroup lang_matlab autocmd! autocmd FileType matlab setlocal ts=4 sw=4 et augroup END
.注意两件事:FileType事件(它在那里,它不是BufRead,BufNewFile)和setlocal而不是普通集.第一个用于文件类型设置,第二个是如何设置特定于缓冲区的选项.
关于为什么perl和ruby设置有效以及为什么matlab设置没有:你的示例代码与之相同
augroup lang_perl autocmd! augroup END augroup lang_ruby autocmd! augroup END set tabstop=4 " tabstop length N in spaces set shiftwidth=4 " make >> and friends (<<,not the default 8 set expandtab " Use spaces instead of tabs set tabstop=2 " tabstop length N in spaces set shiftwidth=2 " make >> and friends (<<,not the default 8 set expandtab " Use spaces instead of tabs
所以,你有效地设置ts = 2 sw = 2 et.但$VIMRUNTIME / ftplugin / perl.vim包含以下代码:
setlocal tabstop=4 setlocal shiftwidth=4
所以,perl的ts = 4 sw = 4设置为ftplugin / perl.vim,而不是你的vimrc(如果你已经安装了perl-support插件).你可以通过在vimrc中用tabstop = 8替换tabstop = 4来检查它.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。