Reduced functionality (FASTER) xml syntax file?

2 views
Skip to first unread message

John Orr

unread,
Dec 1, 2008, 1:44:03 PM12/1/08
to Vim Use
Hi All,

Recently I've been editing a number of xml files - and I've found vim
lagging sorely behind my scrolling when I hold down j or k. My computer
is less than 6 months old and quite quick, which had me wondering why vim
was so slow. Disabling syntax highlighting proved to solve the problem -
but I was wondering, has anyone else hit this problem, and perhaps created
a reduced functionality xml syntax highlighter - so I still get something
useful, but maybe not quite as complex?

(Even better, of course, would be a setting to reduce the functionality of
the existing syntax file...)

Thanks very much,
John

Gene Kwiecinski

unread,
Dec 1, 2008, 2:14:03 PM12/1/08
to vim...@googlegroups.com
>was so slow. Disabling syntax highlighting proved to solve the problem
-
>but I was wondering, has anyone else hit this problem, and perhaps
created
>a reduced functionality xml syntax highlighter - so I still get
something
>useful, but maybe not quite as complex?

One person's opinion of what constitutes "stripped down" would likely
differ from someone else's opinion, which is the problem. Eg, you might
be happy with just tagstoff being one color, and textstoff being a
different color. Someone else might want attributes to be a 3rd color.
Someone else would make comments a different color. Before you know it,
you'd have a "stripped down" syntax file that's maybe 80% of the
original, not saving much.

<shrug/>

David Fishburn

unread,
Dec 1, 2008, 2:44:33 PM12/1/08
to vim...@googlegroups.com
This is a simple work around that seems to keep things moving for me.
I define the following in my vimrc.

function! Format_SGML() range
" Add a new line to the bottom of the mark to be removed later
call cursor(a:lastline,1)
put =''
silent! exec "ma z"
" Add a new line above the mark to be removed later
call cursor(a:firstline,1)
put! = ''
silent! exec "ma y"

" Record current filetype
let save_ft = &filetype

if save_ft != 'xml'
" Change the filetype so we can format the selection
setlocal filetype=xml
endif

" Put each tag on a newline
exec line("'y").','.line("'z").'s/>\s*</>\r</ge'
" Reformat using Vim's indenter
call cursor(line("'y"),1)
exec 'normal! '.(line("'z")-line("'y")+1).'=='

if save_ft != 'xml'
" Restore the filetype
exec 'setlocal filetype='.save_ft
endif

" Delete the additional lines added
silent! exe "norm! 'ydd'zdd"
endfunction
command! -range=% -nargs=0 FormatSGML <line1>,<line2>call Format_SGML()

Then each time I open the file I run:
:FormatSGML

It seems when the lines are shorter, the highlighting is quick.

HTH,
Dave

Erik Falor

unread,
Dec 1, 2008, 2:45:55 PM12/1/08
to vim...@googlegroups.com, jo...@vastsystems.com.au
On Tue, Dec 02, 2008 at 05:44:03AM +1100, John Orr wrote:
> has anyone else hit this problem, and perhaps created
> a reduced functionality xml syntax highlighter - so I still get something
> useful, but maybe not quite as complex?
>

I personally run into this most frequently when editing an XML file
with really long lines.

I just adjust 'synmaxcol' to something like 128 and Vim speeds right
back up. The trade-off being that only the first 128 characters in a
line are highlighted.

Read
:help 'synmaxcol'
for more info.

--
Erik Falor
Registered Linux User #445632 http://counter.li.org

John Orr

unread,
Dec 1, 2008, 3:10:37 PM12/1/08
to vim...@googlegroups.com
Thanks David, an innovative solution.
I'm not quite sure what I'm doing wrong but the function isn't doing
anything for me though.
It prints out a decrementing status of how many lines are left to format,
so it seems to be working, but nothing gets formatted.
I suspected it was because I had tw=0 but setting it to 60 didn't help.

Any easy ideas? Otherwise, the synmaxcol suggestion may well be
sufficient.

(I could send you debug output - scriptnames, or other things - but I
don't want to waste you time unless you're keen.)

Thanks very much anyway,
John
--
John Orr
+61 405 086 850
SkypeId: qpkorr

John Orr

unread,
Dec 1, 2008, 3:12:35 PM12/1/08
to vim...@googlegroups.com
Thanks David, an innovative solution.
I'm not quite sure what I'm doing wrong but the function isn't doing
anything for me though.
It prints out a decrementing status of how many lines are left to format,
so it seems to be working, but nothing gets formatted.
I suspected it was because I had tw=0 but setting it to 60 didn't help.

Any easy ideas? Otherwise, the synmaxcol suggestion may well be
sufficient.

(I could send you debug output - scriptnames, or other things - but I
don't want to waste you time unless you're keen.)

Thanks very much anyway,
John


On Tue, 02 Dec 2008 06:44:33 +1100, David Fishburn
<dfishb...@gmail.com> wrote:

>

John Orr

unread,
Dec 1, 2008, 3:15:14 PM12/1/08
to vim...@googlegroups.com
Thanks very much Erik, that seems to work very well and is probably a good
trade-off.

John

John Orr

unread,
Dec 1, 2008, 3:25:51 PM12/1/08
to vim...@googlegroups.com
I may have worked out the problem, perhaps - and it's the xml files I'm
looking at.

The dtd/schema is poor - with lots of attributes which should be elements
- so each element gets very long, and perhaps Vim keeps it together??

Anyway - synmaxcol is working well.

Thanks,
John

On Tue, 02 Dec 2008 07:12:35 +1100, John Orr <jo...@vastsystems.com.au>
wrote:
Reply all
Reply to author
Forward
0 new messages