11
votes

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

4 Answers

19
votes

You can set :syntax manual and then enable it with set syntax=ON in the buffers you like. Also see :help :syn-manual.

6
votes

Answering my own question: A simple hack would be to force the syntax of the file to something that vim doesn't know how to highlight: :set syntax=unknown

However, this seems a bit hacky - maybe there's another solution?

4
votes

For large-file editing I usually use Chip's LargeFile plugin. It disables syntax highlighting, undo database and other features that give trouble with large files.

0
votes

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.