Editing xml files with long lines is really slow in vim. What can I do to fix this?

后端 未结 13 962
情书的邮戳
情书的邮戳 2021-01-31 02:24

I edit a lot of xml files with vim. The problem is that, because of the long lines, navigation/editing in vim is extremely slow. Is there something I can do (besides turning off

13条回答
  •  感情败类
    2021-01-31 02:46

    You can this function to your .vimrc to reformat your xml file and hopefully reduce line length.

    function! DoPrettyXML()
      " save the filetype so we can restore it later
      let l:origft = &ft
      set ft=
      " delete the xml header if it exists. This will
      " permit us to surround the document with fake tags
      " without creating invalid xml.
      1s///e
      " insert fake tags around the entire document.
      " This will permit us to pretty-format excerpts of
      " XML that may contain multiple top-level elements.
      0put =''
      $put =''
      silent %!xmllint --format -
      " xmllint will insert an  header. it's easy enough to delete
      " if you don't want it.
      " delete the fake tags
      2d
      $d
      " restore the 'normal' indentation, which is one extra level
      " too deep due to the extra tags we wrapped around the document.
      silent %<
      " back to home
      1
      " restore the filetype
      exe "set ft=" . l:origft
    endfunction
    
    command! PrettyXML call DoPrettyXML()
    

提交回复
热议问题