diff --git a/lua/custom/plugins/xml.lua b/lua/custom/plugins/xml.lua new file mode 100644 index 00000000..8a874536 --- /dev/null +++ b/lua/custom/plugins/xml.lua @@ -0,0 +1,23 @@ +local function setup_format_xml_command() + local python_code = [[ +import vim +import xml.dom.minidom + +def format_xml(): + buf = vim.current.buffer + xml_data = '\n'.join(buf) + dom = xml.dom.minidom.parseString(xml_data) + pretty_xml = dom.toprettyxml() + formatted_lines = pretty_xml.split('\n') + buf[:] = formatted_lines + +format_xml() +]] + + vim.api.nvim_command("command! FormatXML :py3 " .. python_code) +end + +-- Call the function to set up the command +setup_format_xml_command() + +return {}