加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在vim中使用Matlab进行自动命令?

发布时间:2020-12-15 22:36:20 所属栏目:安全 来源:网络整理
导读:我每天都使用几种不同的编程语言,我希望每种语言都有不同的标签宽度(空格).例如:我使用 Ruby的“标准”2空格,但我们现有的所有Matlab代码都使用4个空格. 我的个人?/ .vimrc有这个: augroup lang_perl au! set tabstop=4 " tabstop length N in spaces set
我每天都使用几种不同的编程语言,我希望每种语言都有不同的标签宽度(空格).例如:我使用 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来检查它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读