vim syntax highlight improve performance
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 scrolljump
option. 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.
Related videos on Youtube
RusAlex
Updated on May 19, 2020Comments
-
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 over 13 yearsEdit smaller files? What vim filetype is selected?
-
Greg Hewgill over 13 yearsMy 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 over 13 yearsI have the same problem with C syntax highlight and foldmethod=syntax.
-
frabjous over 13 yearsThe colorscheme might make a difference too. Try a number of them.
-
RusAlex over 13 yearsIm 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 about 12 yearsThe cause of slow vim files most of the time is long lines: stackoverflow.com/questions/901313/…
-
-
RusAlex over 12 yearsthanks, i will try, but now i have intel i7 sandy bridge core, and don't see any freezes =)
-
aphax over 12 yearsThanks for the 'nocursorline' tip. I've suffered from gvim being somewhat sluggish for a long time, and disabling cursorline made a considerable difference
-
dsummersl almost 11 yearsI don't know what
syntax sync minlines
means exactly, but it worked wonders for large PHP that I edit. Thanks! -
Steven Lu about 10 yearsIt is insane that
cursorline
makes such a huge difference. I brought my vimrc to my raspberry pi, andnocursorline
basically gave me a speed boost of between 500% and 1000% immediately. No joke.top
confirms: 95+% CPU (and very delayed) drops to ~20%, justj
andk
moving up and down. Editing a large file basically went from impossible to moderately sluggish. I have a 1000+ line vimrc. +1