indenting XML in vim

Sometimes I need to look inside XML files which consist of one big line. It's very impossible, and reformatting takes a time. Fortunately, I've found a good solution for vim.

I added to my ".vimrc" file:

map <F2> <Esc>:1,$!xmllint --format -<CR>

Now I can press "F2" button, and vim indents the text.

More hints on indenting XML in vim: Tip #349: Format your xml document using xmllint.

Vibe code with your voice

Stop fighting speech recognition.
Just talk → fix mistakes later

"... _brings_ hello world"   ❌
          ↓
"... _prints_ hello world"   ✅

Get handsfree.vc on Google Play

Categories: vim

Updated: