在 Vim 中编辑 Yaml 时缩进错误 [英] Wrong indentation when editing Yaml in Vim
问题描述
Vim 似乎对 YAML 文件中的破折号没有正确反应,因此破坏了格式.
Vim does not seem to correctly react at a dash symbol in YAML files therefore breaking the format.
例如我有一个块应该是这样的:
For example I have a block which should look like this:
handlers:
- name: restart exim4
service: name=exim4 state=restarted
当我完成输入 restart exim4
并输入 service:
Vim 重新缩进我最后的 service
行:
When I finish typing restart exim4
and type service:
Vim reindents my final service
line:
handlers:
- name: restart exim4
service: name=exim4 state=restarted
很明显,Vim 试图按列对齐句子,但这不是 YAML 所需要的.我想创建一个包含两个值的数组.
So clearly Vim tries to align sentences column-wise but that's not what is needed in YAML. I want to create an array with two values.
如何解决这个问题?
推荐答案
安装这个插件:
https://github.com/chase/vim-ansible-yaml
它是为 Ansible 设计的,但理论上它适用于所有类型的 YAML 文件.不幸的是,如果您不使用与 ansible 相关的文件,您将不得不 :set filetype=ansible.
It is made with Ansible in mind, but in theory it will work with all kinds of YAML files. You will have to :set filetype=ansible unfortunately, if you are not working with ansible related files.
这篇关于在 Vim 中编辑 Yaml 时缩进错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!