vim 中的多个自动命令 [英] Multiple autocommands in vim

查看:35
本文介绍了vim 中的多个自动命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 .vimrc 中有一些部分如下所示:

I've got some sections in my .vimrc that look like this:

autocmd Filetype ruby setlocal ts=2
autocmd Filetype ruby setlocal sts=2
autocmd Filetype ruby setlocal sw=2

现在看来我可以将它们转换成这样:

now it seems I can convert them to this:

autocmd Filetype ruby setlocal ts=2 sts=2 sw=2

但这是我的问题:有没有一种 vim 方式来拥有这样的结构?

but here's my question: is there a vim way to have a structure like this?

<something mentioning Filetype ruby>
  setlocal ts=2
  setlocal sts=2
  ...
<end>

即,autocmd Filetype 位能否以某种方式处理一组操作?(这是一个简单的例子,我真的要求更复杂的情况.)

ie, can the autocmd Filetype bit somehow be made to address a group of actions? (this is a simple example, I'm really asking for more complicated situations.)

推荐答案

你可以调用一个函数,如果你喜欢:

You can call a function, if you like:

autocmd Filetype ruby call SetRubyOptions()
function SetRubyOptions()
    setlocal ts=2
    ...
endfunction

这篇关于vim 中的多个自动命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆