如何使用 Vim 和 Yaml 获得出色的自动缩进?
现在我正在使用 设置自动缩进
当我在 Vim 中编辑 Yaml 文件时,只需在开始新行时复制上一行的缩进即可。不过,我忍不住觉得它可以更聪明一点。如果在之后开始新的一行那就太好了 foo:“酒吧”
可以保持相同的缩进级别,但在之后开始一行 富: 将添加额外的缩进级别。
Right now I am usingset autoindent
when I edit Yaml files in Vim, and it works okay by just copying the previous line's indent when you start a new line. I can't help but feel like it could be a little smarter, though. What would be great is if starting a new line afterfoo: "bar"
could keep the same indent level, but starting a line afterfoo:
would add an additional level of indent.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Xavier 启发我对此进行了一些修改,我想出了我自己的 Yaml 缩进脚本。它不处理任何更高级的 Yaml 功能,但它可以满足我最初的要求。
要使用它,您只需将其放入
~/.vim/after/ftplugin/yaml.vim
(假设您正在使用set ftplugin on
)。Xavier inspired me to hack at this a bit, and I came up with my own little indent script for Yaml. It doesn't handle any of the more advanced Yaml features, but it does what I originally asked for.
To use this, you can just drop it into
~/.vim/after/ftplugin/yaml.vim
(assuming you are usingset ftplugin on
).具体的缩进规则按语言存储在:
$VIMRUNTIME\indent\foo.vim
表示语言foo
。在我的默认安装中,我有
ruby.vim
、haml.vim
和许多其他文件,但没有yaml.vim
。您可以创建一个
indent\yaml.vim
来获取您想要的缩进规则。我很快尝试在网上搜索是否有类似的东西,但我没有找到任何东西。Specific indentation rules are stored on a language basis in :
$VIMRUNTIME\indent\foo.vim
for languagefoo
.On my default installation, I have got
ruby.vim
,haml.vim
and many other but noyaml.vim
.You could create an
indent\yaml.vim
to get the indentation rules you want. I have quickly tried to search online if something similar was available but I have not find anything.