I'm trying to reindent current HTML file with this command from inside vim :

:!xmllint --html --format % 2>/dev/null

But, all it does it displays the output to stdout without actually modifying the file.

EDIT0 : I just found this but I'm not sure if this the correct way to do this :

:%!xmllint --html --format - 2>/dev/null

:% stands for the vim range :1,$ (the entire file) and - tells xmllint to read data from stdin

EDIT1 : @statox, Finally, I'll be using equalprg :

autocmd FileType html let &l:equalprg='xmllint --html --format --recover - 2>/dev/null' "Pretty print HTML when 'gg=G' is pressed

Here's some vim help about the let & syntax:

:h let-&
:let &{option-name} = {expr1}                   :let-option :let-&
                        Set option {option-name} to the result of the
                        expression {expr1}.  A String or Number value is
                        always converted to the type of the option.
                        For an option local to a window or buffer the effect
                        is just like using the :set command: both the local
                        value and the global value are changed.
                                :let &path = &path . ',/usr/local/include'
                        This also works for terminal codes in the form t_xx.
                        But only for alphanumerical names.  Example:
                                :let &t_k1 = "\<Esc>[234;"
                        When the code does not exist yet it will be created as
                        a terminal key code, there is no error.

:let &l:{option-name} = {expr1}
:let &l:{option-name} .= {expr1}
:let &l:{option-name} += {expr1}
:let &l:{option-name} -= {expr1}
                        Like above, but only set the local value of an option
                        (if there is one).  Works like :setlocal.

:let &g:{option-name} = {expr1}
:let &g:{option-name} .= {expr1}
:let &g:{option-name} += {expr1}
:let &g:{option-name} -= {expr1}
                        Like above, but only set the global value of an option
                        (if there is one).  Works like :setglobal.
  • 3
    What you have in your edit is what I would do, so I would say it's correct.
    – Heptite
    Jul 11, 2021 at 21:52
  • 1
    I think I'd rather use :h 'equalprg' but you can check the different answers to this question which should give you the information you need.
    – statox
    Jul 12, 2021 at 11:47
  • @statox Thanks for your solution. I've added it in my EDIT1 by replacing setlocal equalprg by let &l:equalprg
    – SebMa
    Jul 12, 2021 at 16:32
  • @SebMa It would be great if you posted your solution as an answer rather than as an edit of your question (and you should mark this answer as accepted): This way future readers will easily know that you got a working solution.
    – statox
    Jul 13, 2021 at 7:05
  • @statox YOU did the solving here. Why not create your answer so that I can award and accept it and then I'll move my EDIT1 from my question inside your new answer ?
    – SebMa
    Jul 13, 2021 at 9:38


Your Answer

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

Browse other questions tagged or ask your own question.