Enable Syntax highlighting in vim on a per-buffer basis

Viewed 3043

I currently have to edit some very large XML files, which slows down syntax highlighting to a point where it's absolutely unusable - it takes multiple seconds to update the screen after a search operation, for example.

When disabling syntax highlighting (:syn off), the same operations happen instantaneously. Unfortunately, disabling syntax highlighting appears to happen globally, so all other files now have it disabled as well.

So: Is there a way to only disable syntax highlighting for a given buffer?

4 Answers

Old topic, but answer may be helpful to others.;)

This is what I lastly use for switching between syntax ON/OFF in the buffer. The change is local to the buffer. Works OK to me.

nnoremap <leader><leader> :call MyLocalSyntaxOnOff()<cr>

function! MyLocalSyntaxOnOff ()
    if getbufvar("%", "&syntax") ==# "OFF"
        setl syntax=ON
        redraw | echo 'Syntax: ON - <space><space> to change.'
    else
        setl syntax=OFF
        redraw | echo 'Syntax: OFF - <space><space> to change.'
    endif
endfunction

Just add it to your .vimrc and You should by fine. ADVISE: Set your leader key (my one is <space> currently), if not - the standard one should be slash (or backslash(?)) key - \.

Best regards.

Related