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

I am editing a lot of xml files using vim. The problem is that due to the long lines, navigation / editing in vim is extremely slow. Is there something I can do (besides disabling syntax highlighting / filetype plugins and file type indents) to be able to edit these files without this delay?

Unsurprisingly, a trivial thing, such as syntax highlighting, is so poorly handled by vim. I do not remember that this was a problem with any other editor. I really enjoy using vim, and I hope there is a way to fix this.

+46
performance xml vim
May 23 '09 at 10:59 a.m.
source share
13 answers

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 
+57
Aug 11 '10 at 17:00
source share

This is 2014, I am using Vim version 7.4. syntax highlighting and a combination of a long line still make vim unacceptably slow. Since this is the first answer received from Google, I wanted to abandon my β€œcurrent” decisions.

  • I found that just turning syntax on and off after loading the intruder file allows vim to behave at an acceptable pace. For convenience, you can tie it

    :syntax off :syntax on

    or bind it: nnoremap <leader>ts :syntax off<cr>:syntax on<cr>

  • I also found that looking for my .vimrc would give the same result

    :source $MYVIMRC

    and required card: nnoremap <leader>sv :source $MYVIMRC<cr>

EDIt ---- 07/31/14

Further research led me to limit the syntax to a maximum column. This worked very well and I had no problems since I am adding below to my vimrc.

 set synmaxcol=250 

this syntax strictly limits the first 250 columns.

+11
Mar 06 '14 at 16:24
source share
 :set nocursorline 

should help.

+10
Aug 29 2018-12-12T00:
source share

How about beautifully printing your XML file (if the line length is the real issue)? You can do this, for example. using xmllint , which is part of the Gnome libxml2 package (and a Windows version is also available).

You can print beautifully in place by doing

 xmllint --format -o xmlFile.xml xmlFile.xml 
+7
May 23 '09 at 11:10
source share

Do you have line break disabled? In my experience, wrapping strings can slow down vim a bit when dealing with very long strings.

 set nowrap 
+7
May 23 '09 at 11:18 a.m.
source share

The simplest and most effective solution I've found is to simply turn off syntax highlighting:
syntax off

This seems to be the culprit when working with long lines. Also, from my experience with vim and xml, the file size doesn't seem to matter - these are long lines that cause these recessions.

Another useful task is to wrap areas with long lines in folds :

  <!--{{{ long lines --> <text>A reeealy long line</text> <!--}}}--> 

Closing bends saves you from parsing the syntax of these lines. Of course, this approach is not always practical, but it worked fine when I had only a few long lines, or they were in a specific area of ​​the file.

Often Vim is still noticeably slower, but in most cases the performance becomes acceptable.

+4
Jul 31. '12 at 16:12
source share

Nope. This is syntax emphasis, I think AFAIK. The Regex approach that Vim uses is not the optimal solution, indeed, for editing xml files.

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

+3
May 23 '09 at 11:02
source share

There is a plugin for work, LargeFile . It disables some events, syntax highlighting and even undo. You did not specify the size of the XML files, but the plugin is customizable. You can set the size of the "large file" in megabytes to normally handle "files that are not large."

+2
May 23 '09 at 20:03
source share

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

+1
May 23 '09 at 11:32
source share

Comment line

 syn sync match xmlSyncDT grouphere xmlDocType +\_.\(<!DOCTYPE\)\@=+ 

in the xml.vim file (using " ).

This problem can be debugged in a vim session by typing :syntime on , doing something that is slow, and then :syntime report . In my case, it reported xmlSyncDT , taking over 10 seconds in my 6 megabyte xml file with 4000 character strings to display the last page of the file. Commenting out the line above did not affect syntax highlighting, as far as I noticed, except that now it does not take more than a second to display the screen.

+1
Oct 22 '15 at 23:32
source share

Add to vimrc file

 nmap <leader>x <Esc>:set filetype=xml<CR>:%s/></>\r</g<CR><ESC>gg=G<Esc>:noh<CR> 

pressing x will automatically print the xml file.

0
Feb 08 2018-12-12T00:
source share

You can use this function for your .vimrc to reformat your XML file and hopefully reduce the length of the string.

 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/<?xml .*?>//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 ='<PrettyXML>' $put ='</PrettyXML>' silent %!xmllint --format - " xmllint will insert an <?xml?> header. it 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() 
0
Jul 18 '14 at 15:31
source share

This is caused by parsing a long string in vim. I finally found that if I remove the following from my .vimrc , the problem is resolved:

 filetype indent plugin on 

Note that this does not work if you type :filetype indent plugin off when editing a file with a long line.

0
Oct 05 '16 at 23:09
source share



All Articles