pearofducks / ansible-vim

A vim plugin for syntax highlighting Ansible's common filetypes
MIT License
796 stars 98 forks source link

Improve ansible_unindent_after_newline to intelligently un-indent to the correct parent block #78

Open rootwyrm opened 5 years ago

rootwyrm commented 5 years ago

This one is really frustrating me.

Load the plugin how you like (I use pathogen still), then:

let g:ansible_unindent_after_newline = 1
let g:ansible_attribute_highlight = "ob"
let g:ansible_extra_keywords_highlight = 1
let g:ansible_normal_keywords_highlight = 'Constant'
let g:ansible_with_keywords_highlight = 'Constant'
let g:ansible_template_syntaxes = { '*.rb.j2': 'ruby' }

Create a new tasks/main.yml and start making some magic, only to find it breaking in the most frustrating ways.

---
- name: This is just a demo
  hosts: "{{ target|default('localhost') }}"

  tasks:
    - name: Show the brokenness.
      ## Prevent fail-into
      when: (ansible_facts['distribution'] == "bananabread")
      template:
        src: some.j2
        dest: /usr/local/etc/some.conf
        - name: This line did not indent even close to correctly.

# vim:ft=yaml.ansible:

But we have let g:ansible_unindent_after_newline = 1 so this should fix it, right? Wrong.

---
- name: This is just a demo
  hosts: "{{ target|default('localhost') }}"

  tasks:
    - name: Show the brokenness.
      ## Prevent fail-into
      when: (ansible_facts['distribution'] == "bananabread")
      template:
        src: some.j2
        dest: /usr/local/etc/some.conf

- name: Well this line has no business being all the way over here.

# vim:ft=yaml.ansible:

More obnoxiously, this is unfixable without killing the plugin. Fix the broken indent, assuming it will reset position, and it does not. Instead it re-indents the whole thing back to 0 and just keeps breaking it over and over.

pearofducks commented 5 years ago

I'm happy to accept a pull request for this, but I'm not interested in solving this problem.

albgus commented 5 years ago

Would it be possible to simply implement an option to disable the indention from this plugin? I find the standard yaml indention logic to be enough but it would still be nice to have the highlighting from this plugin while not having to work around the indention.

savchenko commented 3 years ago

Would it be possible to simply implement an option to disable the indention from this plugin?

Sounds like a reasonable balance between cost of implementation and end-effect. @pearofducks , would you accept pull request for such option?

pearofducks commented 3 years ago

This should already be doable with standard Vim config support. No support should be needed from this plugin to reset indentexpr.