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

Viewed 9797

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 syntax highlighting/filetype plugins and filetype indentation) to be able to edit these files without all that lag?

It's really frustrating that a trivial thing such as syntax highlighting is being handled so poorly by vim. I don't remember this being an issue with any other editor. I really like using vim and I hope there is some way to fix this.

13 Answers

Do you have line wrapping disabled? In my experience line wrapping can slow vim down a bit when working with very long lines.

set nowrap

How about pretty-printing your XML file (if the line length is the real problem)? You could do that e.g. using xmllint which is part of the Gnome libxml2 package (and there is also a version available for Windows).

You can pretty-print in-place by executing

xmllint --format -o xmlFile.xml xmlFile.xml

Nope. It's the syntax highlighting think, AFAIK. Regex approach Vim is using is not the optimal solution, really, for editing xml files.

(of course, you can always try writing your own syntax file for xml, in hope you'll do a better job)

There is a plugin, LargeFile for the job. It disables some events, syntax highlighting and even undo. You did not mention about the size of the XML files, but the plugin is configurable. You can set the size of a "large file" in megabytes so that "files that are not large" can be treated normally.

I often replace >< with >\r< -> :s/>\s*</>\r</g and then reindent the whole file with gg=G.

It's caused by long line parsing in vim. I finally found that if I remove following from my .vimrc, the problem solved:

filetype indent plugin on

Note that it doesn't work if you type in :filetype indent plugin off when editing a file with long line.

Related