autocmds.lua (1012B)
1 -- Detect Ansible YAML files and set yaml.ansible filetype 2 -- so ansiblels activates instead of (or alongside) yamlls 3 vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, { 4 pattern = { 5 "*/tasks/**/*.yml", "*/tasks/**/*.yaml", 6 "*/handlers/**/*.yml", "*/handlers/**/*.yaml", 7 "*/roles/**/*.yml", "*/roles/**/*.yaml", 8 "*/playbooks/**/*.yml", "*/playbooks/**/*.yaml", 9 "*/group_vars/**", "*/host_vars/**", 10 "**/site.yml", "**/site.yaml", 11 "**/playbook.yml", "**/playbook.yaml", 12 }, 13 callback = function() 14 vim.bo.filetype = "yaml.ansible" 15 end, 16 }) 17 18 -- Highlight on yank 19 vim.api.nvim_create_autocmd("TextYankPost", { 20 callback = function() 21 vim.highlight.on_yank() 22 end, 23 }) 24 25 -- Remove trailing whitespace on save 26 vim.api.nvim_create_autocmd("BufWritePre", { 27 pattern = { "*.py", "*.sh", "*.yml", "*.yaml", "*.tf", "*.lua" }, 28 callback = function() 29 local pos = vim.api.nvim_win_get_cursor(0) 30 vim.cmd([[%s/\s\+$//e]]) 31 vim.api.nvim_win_set_cursor(0, pos) 32 end, 33 })