0

I am using ansible.vim I am loading it with lazy:

return {
 'pearofducks/ansible-vim',
}

and this is the configuration I have for ansiblels:

      ["ansiblels"] = function()
                lspconfig.ansiblels.setup({
                    filetypes = {
                        "ansible",
                        "yaml.ansible",
                        "yaml.ansible_hosts"
                    },
                    settings = {
                        ansible = {
                            validation = {
                                lint = {
                                    arguments = "-c ~/.config/ansible-lint.yml"
                                }
                            }
                        }
                    }
                })
            end

The plugin ftdetect https://github.com/pearofducks/ansible-vim/blob/master/ftdetect/ansible.vim#L34-L36 creates this group:

augroup ansible_vim_ftyaml_ansible
  au!
  au BufNewFile,BufRead * if s:isAnsible() | set ft=yaml.ansible | en
augroup END

But I would like to use ft=ansible instead of ft=yaml.ansible (so that I can get all the syntax highlights if using yaml.ansible, I lose all the jinga2file type)

I tried this:

    vim.api.nvim_create_autocmd({
        "BufRead",
        "BufNewFile"
    }, {
        pattern = {
            "*/ansible/*.yml",
            "*/tasks/*.yml"
        },
        callback = function()
            vim.bo.filetype = "ansible"
        end
    })

But for an unknown reason, I still get the filetype yaml.ansible instead of only ansible

How could I modify the group to be instead:

augroup ansible_vim_ftyaml_ansible
  au!
  au BufNewFile,BufRead * if s:isAnsible() | set ft=ansible | en
augroup END

But without altering the plugin, is there a way to overwrite this?

1 Answer 1

0

I fixed the problem by loading my custom options after the plugin, the order of loading the plugins and custom options matters, I changed my init.lua from:

require("user.options")
require("user.keymaps")
require("user.lsp-diagnostic")
require("user.lazy")

to:

-- order matters
require("user.keymaps")
require("user.lsp-diagnostic")
require("user.lazy")
require("user.options")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.