tags:

views:

524

answers:

6

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.

+2  A: 

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)

ldigas
+5  A: 

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
0xA3
That is useful indeed but doesn't help when there's a ton of attributes which make the line long ...
@naumcho: It might not be possible with xmllint, but you can write your own pretty-printer that will also put attributes on a new line.
0xA3
+1  A: 

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
therefromhere
yes. wrapping is disabled.
+1  A: 

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

Luc Hermitte
Maybe the problem is indentation. I don't recall having these slow downs while editing non-indented SGML files.I'll try removing the indentation and see if that helps.
+1  A: 

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.

Caglar Toklu
A: 

The problem is that VIM syntax-highlighting is slow for long lines. An easy fix that only slightly degrades functionality is to limit syntax highlighting to the first x columns. Something like this in your .vimrc:

set synmaxcol=120
Gabe Moothart