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

后端 未结 13 937
情书的邮戳
情书的邮戳 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:25

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

    0 讨论(0)
  • 2021-01-31 02:26

    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.

    0 讨论(0)
  • 2021-01-31 02:29

    It is 2014, I am using Vim version 7.4. the syntax highlighting and Long line combination still causes vim to behave unacceptably slow. As this is the first response returned from Google I wanted to drop my "current" solutions.

    • I have found that simply toggling your syntax on and off after loading the offending file allows vim to behave at an acceptable pace. For convenience you can bind it

      :syntax off :syntax on

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

    • I have also found that sourcing my .vimrc will produce the same result

      :source $MYVIMRC

      and obligatory map: nnoremap <leader>sv :source $MYVIMRC<cr>

    EDIt ---- 07/31/14

    Further exploration has lead me to limit the syntax with a maximum column. This has worked very well and I haven't had any problems since I've add the below to my vimrc.

    set synmaxcol=250
    

    this limits syntax generously to the first 250 columns.

    0 讨论(0)
  • 2021-01-31 02:33

    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
    
    0 讨论(0)
  • 2021-01-31 02:39

    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
    
    0 讨论(0)
  • 2021-01-31 02:46
    :set nocursorline
    

    should help.

    0 讨论(0)
提交回复
热议问题