vim syntax highlight improve performance

10,268

Solution 1

Try these settings:

set nocursorcolumn
set nocursorline
set norelativenumber
syntax sync minlines=256

Also check http://vim.wikia.com/wiki/Fix_syntax_highlighting

Solution 2

I was having an issue with slow performance from vim when editing certain CSS files.

I discovered that the cause in my case was large inline images using data urls.

To speed things up, I just modified my .vimrc like so:

set synmaxcol=200  

This did the trick for me. Hope it helps someone else. Hat tip to https://superuser.com/questions/302186/vim-scrolls-very-slow-when-a-line-is-to-long

Solution 3

You can use the scrolljumpoption. The scrolling won't be smoother but rather than scrolling line by line, it will scroll of scrolljump lines at once.

You can try :
set scrolljump=5

It does not solve your root issue, but it is a workaround.

Solution 4

For large files vim will read the whole file in order to determine the context for accurate syntax highlighting.

Setting a maximum number of lines to scan will greatly increase performance, at the potential cost of accurate syntax highlighting.

Add the following to your .vimrc

autocmd BufEnter * :syn sync maxlines=500

This will set the maximum syntax buffer size to 500 lines.

Share:
10,268

Related videos on Youtube

RusAlex
Author by

RusAlex

Updated on May 19, 2020

Comments

  • RusAlex
    RusAlex almost 4 years

    How do I improve performance when I'm scrolling my files and coding them? With syntax highlighting, vim is so slow. When I switch it off, everything is ok. Is there a way or any recommendations to make it faster?

    • DigitalRoss
      DigitalRoss over 13 years
      Edit smaller files? What vim filetype is selected?
    • Greg Hewgill
      Greg Hewgill over 13 years
      My syntax highlighting is fine. Which version of Vim are you using? Normal text/console mode or gVim? Which operating system? Running vim locally or remote? Who created the syntax rules file? How fast is "so slow" - can you quantify the speed?
    • skeept
      skeept over 13 years
      I have the same problem with C syntax highlight and foldmethod=syntax.
    • frabjous
      frabjous over 13 years
      The colorscheme might make a difference too. Try a number of them.
    • RusAlex
      RusAlex over 13 years
      Im using php syntax highlight file from vim distro. php.vim and sometimes when alot of functions on the screen, it freeze when scrolling. i use gVim on my ubuntu
    • Andriy Drozdyuk
      Andriy Drozdyuk about 12 years
      The cause of slow vim files most of the time is long lines: stackoverflow.com/questions/901313/…
  • RusAlex
    RusAlex over 12 years
    thanks, i will try, but now i have intel i7 sandy bridge core, and don't see any freezes =)
  • aphax
    aphax over 12 years
    Thanks for the 'nocursorline' tip. I've suffered from gvim being somewhat sluggish for a long time, and disabling cursorline made a considerable difference
  • dsummersl
    dsummersl almost 11 years
    I don't know what syntax sync minlines means exactly, but it worked wonders for large PHP that I edit. Thanks!
  • Steven Lu
    Steven Lu about 10 years
    It is insane that cursorline makes such a huge difference. I brought my vimrc to my raspberry pi, and nocursorline basically gave me a speed boost of between 500% and 1000% immediately. No joke. top confirms: 95+% CPU (and very delayed) drops to ~20%, just j and k moving up and down. Editing a large file basically went from impossible to moderately sluggish. I have a 1000+ line vimrc. +1